I have a solution file (MySolution.sln) with one project in it (MyProject.vcxproj). I would like to fulfill a custom goal (MyCustomTarget) in my project with a solution. It will look something like this:
msbuild MySolution.sln /t:MyCustomTarget
When I execute the command, I get an error message:
MySolution.sln.metaproj: error MSB4057: The target project "MyCustomTarget" does not exist in the project. [MySolution.sln]
You can replace MyCustomTarget with any standard objects from Microsoft.Cpp.Win32.targets (for example, ClCompile, Link) or any other target choice you include from .targets files in MyProject.vcxproj. None of them will work.
If the msbuildemitsolution environment variable is set to 1, I can check the generated MySolution.sln.metaproj file. At the bottom there are 4 goals: assembly, rebuilding, cleaning and publishing. Using these goals instead of MyCustomTarget, the project builds normally. In addition, if I specify a project file instead of a solution file, it will also be built:
msbuild MyProject.vcxproj /t:MyCustomTarget
But using this format, I will lose the OutDir property, I must manually install the configuration and platform, so I just lose the benefits of having a solution file.
Can I use my custom target with the original solution file that I originally planned?
, , msbuild (mysolution.sln.metproj), MyProject.vcxproj, .targets. , MyCustomTarget .
msbuild :
msbuild MyProject.vcxproj /t:MyCustomTarget /p:Configuration=MyConfig;Platform=MyPlatform;OutDir=MySolution\Platform_MyConfig\
, , .