(All decisions made before and after the event). MSBuild target runs on command line, but not in VS

Basically, I'm trying to implement some preliminary and post-build events for the entire solution, and not just for individual projects. I saw this question here before, but did not address the same issue. I created two .targets files named after.TestSolution.sln.targets and before.TestSolution.sln.targets. Inside each:

front

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="CreateFile" BeforeTargets="Build"> <Message Text="Creating a file" Importance="high" /> <Exec Command="C:\users\me\Desktop\CreateFiles.bat" /> </Target> </Project> 

after

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Target Name="CopyFile" AfterTargets="Build"> <Message Text="Copying a File" Importance="high" /> <Exec Command="C:\users\me\Desktop\CopyFiles.bat" /> </Target> </Project> 

These are just simple test batches to see if events work. Then I create the solution through MSBuild from the command line: this works completely. MSBuild executes the code inside the "before" before building the solution, and the same for the "after" after. HOWEVER, the problem is that I am going to build a solution from VS, the parties never start. So I'm not sure why that is. I am new to MSBuild tasks.

+4
source share
1 answer

This is a known VS function / bug . As already mentioned, VS is not built in the same way as msbuild. Msbuild on the command line generates the msbuild file from the solution (if you set the MSBUILDEMITSOLUTION environment variable to 1, you will see the .metaproj file generated for your solution, which is imported before / after the goals). This is my understanding of V.S. does not do this, but instead calls the msbuild program code without extension points to solve.

+2
source

Source: https://habr.com/ru/post/1500778/


All Articles