dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Solution build target Project:Task doesn't work #3679

Open iskiselev opened 6 years ago

iskiselev commented 6 years ago

In some conditions attempt to build solution with target Project:Task doesn't work.

Steps to reproduce

Reproducible with at least VS 15.8.2

  1. Create new Project/Solution using Service Fabric Application template (name it SFApplicationColon) and add there .Net Framework Stateless Service when it will ask (or use sample1.zip)
  2. Try to build it using command line msbuild /t:SFApplicationColon:Package -- it works as expected
  3. Right click on SFApplicationColon project and select Add -> New Service Fabric Service.. and select .Net Core Stateless Service, build and save all (or use sample2.zip).
  4. Try to build it again using command line msbuild /t:SFApplicationColon::Package -- it doesn't work anymore with "Error MSB4057: The target "SFApplicationColon:Package does not exist in the project."

If you'll use attached samples, please start with nuget restore.

rainersigwald commented 6 years ago

In your sample2, the default solution configuration (Debug|Any CPU) has only a single project enabled:

image

I see the same thing when I follow your steps to add the second project:

diff --git a/SFApplicationColon.sln b/SFApplicationColon.sln
index 146352e..ae891cc 100644
--- a/SFApplicationColon.sln
+++ b/SFApplicationColon.sln
@@ -7,22 +7,38 @@ Project("{A07B5EB6-E848-4116-A8D0-A826331D98C6}") = "SFApplicationColon", "SFApp
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stateless1", "Stateless1\Stateless1.csproj", "{8E92BE02-657C-494C-AA50-7E1564550DFB}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stateless2", "Stateless2\Stateless2.csproj", "{041340E4-CAA8-4284-BF7B-88274D6B3E62}"
+EndProject
 Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
+       Debug|Any CPU = Debug|Any CPU
        Debug|x64 = Debug|x64
+       Release|Any CPU = Release|Any CPU
        Release|x64 = Release|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
+       {30020D75-DB56-4BCF-A5A6-6A951989694E}.Debug|Any CPU.ActiveCfg = Debug|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Debug|x64.ActiveCfg = Debug|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Debug|x64.Build.0 = Debug|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Debug|x64.Deploy.0 = Debug|x64
+       {30020D75-DB56-4BCF-A5A6-6A951989694E}.Release|Any CPU.ActiveCfg = Release|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Release|x64.ActiveCfg = Release|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Release|x64.Build.0 = Release|x64
        {30020D75-DB56-4BCF-A5A6-6A951989694E}.Release|x64.Deploy.0 = Release|x64
+       {8E92BE02-657C-494C-AA50-7E1564550DFB}.Debug|Any CPU.ActiveCfg = Debug|x64
        {8E92BE02-657C-494C-AA50-7E1564550DFB}.Debug|x64.ActiveCfg = Debug|x64
        {8E92BE02-657C-494C-AA50-7E1564550DFB}.Debug|x64.Build.0 = Debug|x64
+       {8E92BE02-657C-494C-AA50-7E1564550DFB}.Release|Any CPU.ActiveCfg = Release|x64
        {8E92BE02-657C-494C-AA50-7E1564550DFB}.Release|x64.ActiveCfg = Release|x64
        {8E92BE02-657C-494C-AA50-7E1564550DFB}.Release|x64.Build.0 = Release|x64
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Debug|Any CPU.Build.0 = Debug|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Debug|x64.ActiveCfg = Debug|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Debug|x64.Build.0 = Debug|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Release|Any CPU.ActiveCfg = Release|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Release|Any CPU.Build.0 = Release|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Release|x64.ActiveCfg = Release|Any CPU
+       {041340E4-CAA8-4284-BF7B-88274D6B3E62}.Release|x64.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE

Passing msbuild /t:SFApplicationColon:Package /p:Platform=x64 works (by forcing into the correct solution configuration).

So it looks like the problem here is a mismatch: the new solution is created with only x64 projects, but the new project experience adds an Any CPU platform, including adding it (first) to the solution. Then, the first listed solution configuration becomes the default in command-line MSBuild invocations, causing this confusion.

This might be a problem with the Service Fabric Tools, or it might be deeper in VS.

Workaround

Specify the solution configuration and platform explicitly

msbuild /p:Configuration=Debug /p:Platform=x64

or

After I deleted the "Any CPU" platform using the solution configuration manager, the command line worked.

(I suspect you could also manually edit the .sln to put the x64 configuration first, and it'd work again, but I haven't tried.)