views:

208

answers:

5

I have a custom build target in a visual studio 2008 c# project. Is there a simple way to add a context menu item to the project, so that the custom build target can be executed via the ide? The build target is not integrated into the default build process and has to be started by hand. This step should be simple for all developers and should not force them to execute msbuild from the command line.

Any hint for a simple, working solution?

regards, Achim

+1  A: 

If you don't want an add-in, you could have a VS macro that registers a command (in the context menu of an item in the solution explorer), which launches this build process.

Timores
Sounds good, but can you give me some more details? Is the macro stored in the solution? If possible, I would like to have self-contained solution which can be checked out from SVN and will just work without further installations.
Achim
A: 

While not contained inside of Visual Studio, I just create .cmd files. Inside of this file you use msbuild.exe to build the project. You can also specify properties and other command line options at the same time. When a developer needs to kick off a build they just double click on the correct .cmd file.

Sayed Ibrahim Hashimi
+1  A: 

You can add another build configuration in addition to Debug and Release and then modify your project to use MSBuild conditions and properties to determine if your custom target should run based on the configuration being built. If you specify the chain appropriately, you should be able to prevent the default build operations occurring in favour of the custom steps you require.

To simplify for all developers, once you've created this special project file, you can export it as a template for use by the rest of the team when creating new projects.

Jeff Yates
Wierd. I swear I hadn't read your answer when I posted mine.
Damien_The_Unbeliever
A: 

In this blog post Scott Hanselman describes how to create a button in VS to call "msbuild /m"

http://www.hanselman.com/blog/CategoryView.aspx?category=MSBuild

You can do the same, but instead you could call:

 msbuild /t:YourTarget

You probably could automate the creation of the button.

Robert
+2  A: 

Add a new configuration to the project/solution. Then, close the project file, and open it for editing in XML. Change it's DefaultTargets attribute to "PickBuild", and add the following target to the bottom of the file:

<Target Name="PickBuild">
    <CallTarget Targets="Build" Condition=" '$(Configuration)' == 'Debug' "/>
    <CallTarget Targets="Build" Condition=" '$(Configuration)' == 'Release' "/>
    <CallTarget Targets="SpecialTarget" Condition=" '$(Configuration)' == 'NewConfiguration' "/>
</Target>

Now, to execute the special task, the developer just needs to switch configuration in Visual Studio and hit build. And, as requested, this lives within the file, so will work on anyone else's machine also

Damien_The_Unbeliever