Pregunta

Basically, I am trying to implement some pre and post build events for an entire solution instead of just standalone projects. I have seen this question around here before, but not addressing the same problem. I have created two .targets files by the name of after.TestSolution.sln.targets and before.TestSolution.sln.targets. Within each:

before

<?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 the events work. I then build the solution through MSBuild from command line: this works fully. MSBuild executes the code within the "before" before the solution builds and the same for the "after" afterwards. HOWEVER, the problem is when I go to build the solution from VS, the batches are never run. So, I am not sure as to why this is. I am fairly new to MSBuild tasks.

¿Fue útil?

Solución

This is a known VS feature/bug. As mentioned, VS does not build in the same way as msbuild. Msbuild on the commandline generates an msbuild file from the solution (if you set the MSBUILDEMITSOLUTION environment variable to 1, you'll see a .metaproj file generated for your solution in which the before/after targets are imported). It's my understanding VS does not do that but instead invokes msbuild programatically with no extension points for the solution.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top