How to customize your MSBuild project file manually
To hand-modify your managed project file, right click on the project, choose Unload, right click again, choose Edit. After editing (with intellisense!) save and close. Right click on the project, choose Reload. (If you are using Beta 2, after unloading the project, do File>Open>File and choose the project file manually.)
As well as modifying properties and items in this editor, you can even add steps to the build. For example, to generate a new file during the build and get it compiled into the assembly, you could add this just before the closing </Project>
<!– Overriding the BeforeCompile target to insert this step just before the compilation step –>
<Target Name="BeforeCompile">
<!– Use Exec task to create a code file; this could be done more elegantly with a custom task–>
<Exec Command="echo static class BuildMachine { public static string Name { get { return "%COMPUTERNAME%"; }}} > buildMachine.cs" Outputs="buildMachine.cs">
<!– Add this file to the list to compile –>
<Output ItemName="Compile" TaskParameter="Outputs" />
</Exec>
</Target>
Now you can use BuildMachine.Name in your project to programmatically get the name of the machine that built the assembly. You could have achieved this specific example in VS 2003 by creating the file in a pre-build event, or using a compiler define, but there is no way in VS 2003 you could have hooked into the middle of the build process as described above. A more elegant use would be to use a custom task to modify your AssemblyInfo.cs file during the build, to increment the AssemblyVersion attribute.
More info on MSBuild is here https://channel9.msdn.com/wiki/default.aspx/MSBuild.HomePage
Comments
- Anonymous
September 20, 2005
The comment has been removed - Anonymous
September 21, 2005
Norman, you're totally right that this command ought to be visible all the time. (And it should automatically unload the project when you Edit, and automatically reload the project when you close the file. And reloading the project should re-open the files you previously had open.) This scenario probably didn't receive the attention it deserved until quite late in the cycle, when there was limited time. I would like it to get much smoother next version.
Thanks for your feedback. You can give other feedback at my team's email below.
Dan (msbuild@microsoft.com) - Anonymous
September 11, 2006
Why IDE Customization Event Handlers like BuildEvents_OnBuildDone() doesn't give access to the project file name which is actually built at last(after all dependent projects are built) ?
I have DeklarIt Tool Installed in IDE, when Deklarit project is built (has an extension of .dklp), it no where is showing the project name from parameters provided by IDE Build Customization Events.