1

I have a solution with many projects organized in solution folders. I am trying to invoke Build target on a project of the solution using solution .sln file. The msbuild errs out saying Build target is not available in the said project. I can invoke Clean target, Rebuild target on the same project, but not build.

Wondering what I am doing wrong. Below is the command line that I am using:

msbuild ..\Galaxy.sln /p:Configuration=Debug /p:"Platform=Any CPU" /t:"DataTools\CLIUtils:Build"

The error: error MSB4057: The target "DataTools\CLIUtils:Build" does not exist in the project. [snip\Galaxy.sln]

I am using Visual Studio 2019. I also checked https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2015/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe?view=vs-2015 which describes target invocation for solutions. This looks like a bug to me.

videoguy
  • 1,732
  • 2
  • 24
  • 49
  • Check the build target in DataTools\CLIUtils. Or you can also try to update the visual studio to see if the problem still exists. – Jingmiao Xu-MSFT Oct 07 '22 at 02:14
  • Build target is default target that the framework provides right? I don't know what to check there? Let me see if I have a system with VS 2022 and check if this issue is still there. – videoguy Oct 07 '22 at 02:39
  • I tried with VS 2022. I still got the same error. – videoguy Oct 07 '22 at 03:46

1 Answers1

1

We can produce an MSBuild file named .sln.metaproj use this method and check this file we can see targets like Clean, Rebuild, Publish, Restore but not Build target.

enter image description here

You can try CoreBuild target, it works in my test:

msbuild ..\Galaxy.sln /p:Configuration=Debug /p:"Platform=Any CPU" /t:"DataTools\CLIUtils:CoreBuild"
Jingmiao Xu-MSFT
  • 2,076
  • 1
  • 3
  • 10
  • You are right. I don't see Build target in the .sln.metaproj for DataTools\CLIUtils:Build. The CoreBuild seemed like it worked, but it didn't. I have Directory.Build.targets file with bunch of targets tied to AfterBuild target. They didn't get invoked with CoreBuild. The meta project is helping me understand how solution invokes project targets. I am coming up with set of targets at solution level using Directory.Solution.targets file – videoguy Oct 08 '22 at 14:23
  • Maybe you can refer to [this](https://stackoverflow.com/a/48069805/17296043) about AfterBuild target in Directory.Build.targets file. Or you can create a new question about this. – Jingmiao Xu-MSFT Oct 10 '22 at 02:11