开发者

Adding a custom build step with a nuget package

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 man开发者_JS百科ually 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜