I have several Visual Studio 2010 C# projects. I'd like to have them all have the same post build event. Basically I want them to copy their output somewhere. I think I can do this using an <import> statement in each csproj file, but I can't seem to figure out the properties/targets and such that I need in the imported file. Do you have any suggestions?
EDIT: I've tried the following but can't get it to work. This is what the Imports.props file looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterBuild">
<Message Text="Here I come to save the day!" />
</Target>
</Project>
I then Include it in the csproj files:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Imports.props" />
...
I've also tried this as Imports.props:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PostBuildEvent>echo Here I come to save the day!</PostBuildEvent>
</PropertyGroup>
</Project>
In the Post-build event command line box, specify the syntax of the build event. Add a call statement before all post-build commands that run . bat files. For example, call C:\MyFile.
Pre/Post build events are useful when we wish to perform some operation before/after a project is built. These operations are nothing but the Shell commands being used from the command line. A build event can be formed using a single, multiple, or conditional commands.
MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.
If an error occurs in the build, the post-build event does not occur; if the error occurs before the linking phase, neither the pre-link nor the post-build event occurs. Additionally, if no files need to be linked, the pre-link event does not occur.
Make sure that you import your targets file after the Microsoft.Common.targets import, as that file defines an empty AfterBuild target, which would override the definition in your targets file.
<import>
in each projectfile and a <AfterBuild>
target in your common build file.
CommonTargets http://msdn.microsoft.com/en-us/library/ms171464.aspx
TargetOrder http://msdn.microsoft.com/en-us/library/ms171462.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With