Skip to content

A non-existing target gets called for F# project during design-time #9012

@vzarytovskii

Description

@vzarytovskii

Visual Studio Version

17.6 and 17.7

Summary

When loading a semingly normal ASP.NET WebAPI solution with 2 F# projects, during design-time build, there's an issue:

Error    MSB4057  

The target "ResolveCodeAnalysisRuleSet" does not exist in the project.  

C:\Program Files\Microsoft Visual Studio\2022\NonIntPreview\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.Managed.DesignTime.targets    

It is normal to not have this target for F#, VS msbuild design time target defines CollectUpToDateCheckInputDesignTimeDependsOn as following:

<PropertyGroup>
	<CollectUpToDateCheckInputDesignTimeDependsOn>CompileDesignTime</CollectUpToDateCheckInputDesignTimeDependsOn>
	<!-- F# projects do not have the ResolveCodeAnalysisRuleSet target. -->
	<CollectUpToDateCheckInputDesignTimeDependsOn Condition="'$(Language)' == 'C#' or '$(Language)' == 'VB'">$(CollectUpToDateCheckInputDesignTimeDependsOn);ResolveCodeAnalysisRuleSet</CollectUpToDateCheckInputDesignTimeDependsOn>
</PropertyGroup>

However, in the binlog I see the following:

Property reassignment: $(CollectUpToDateCheckInputDesignTimeDependsOn)="CompileDesignTime;ResolveCodeAnalysisRuleSet" (previous value: "CompileDesignTime") at C:\Program Files\Microsoft Visual Studio\2022\NonIntPreview\MSBuild\Microsoft\VisualStudio\Managed\Microsoft.Managed.DesignTime.targets (443,5)
Property reassignment: $(Language)="F#" (previous value: "C#") at C:\Program Files\Microsoft Visual Studio\2022\NonIntPreview\Common7\IDE\CommonExtensions\Microsoft\FSharp\Tools\Microsoft.FSharp.Targets (43,9)

It seems that language gets assigned to C# and then reassigned to F# after the CollectUpToDateCheckInputDesignTimeDependsOn is set.

To summarize: non-existing target ResolveCodeAnalysisRuleSet gets assigned to CollectUpToDateCheckInputDesignTimeDependsOn and later on becomes a source of break in design-time build, making F# intellisense unusable for such projects, because of F# gets set as a Language only after it.

Steps to Reproduce

Clone the following repository, open in VS 17.6 or 17.7: https://github.com/vzarytovskii/webapi-proj-system-issue
Issue doesn't reproduce if GitVersion.MsBuild package is removed, which leads me to believe that it resets the language or something, however it was not an issue in 17.5.

Expected Behavior

Language is set before assigning targets, or non-existed target is not getting invoked.

Actual Behavior

Language is set after assigning targets and non-existed target gets invoked.

User Impact

Project builds, but majority intellisense and language features do not work (workaround exists).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature-Up-to-dateBuild up-to-date check that avoids shelling out to MSBuild unless necessary.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions