Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a custom build step with a nuget package

Tags:

nuget

envdte

I am developing a nuget package which will set up the current project to use my company's assembly versioning standard. I've got it doing everything I want (so far) smoothly apart from adding in a custom build step.

Historically this has been done manually by editing the .csproj file directly and adding in a couple of new tags into the xml. These are ...

  • Property Group
  • Target

It actually adds them in successfully, but i've done it by editing the xml rather than via the EnvDTE object in the $project parameter in install.ps1. But I get a message popping up asking my if I want to discard my changes.

I've added $project.Save() to my script just before I make the changes and that gets rid of the popup, and I just get the one telling me the project has changed and asking me if I want to reload it. Which is better, but still not quite perfect.

Is there a better way to do this?

like image 379
Antony Scott Avatar asked Jun 29 '11 13:06

Antony Scott


2 Answers

You can also use the NuGetPowerTools package written by David Fowler (NuGet lead developer).

Install-Package NuGetPowerTools

Add it as a dependency to your package, then in the install.ps1 script, you can call:

Add-Import "\Path\To\Import.targets" $project.ProjectName
Set-MSBuildProperty "MyPropertyName" "MyPropertyValue" $project.ProjectName

$value = Get-MSBuildProperty "MyPropertyName" $project.ProjectName

Check out the code at https://github.com/davidfowl/NuGetPowerTools for more info.

like image 60
Kiliman Avatar answered Nov 09 '22 00:11

Kiliman


Scott Hanselman did this at mix11. His technique was to unload the project (using DTE), modify it using PowerShell, then reload it (using DTE again).

http://channel9.msdn.com/Events/MIX/MIX11/FRM09

like image 26
Damian Powell Avatar answered Nov 08 '22 22:11

Damian Powell