Adding a custom build step with a nuget package

2019-04-07 07:02发布

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?

标签: nuget envdte
2条回答
爷、活的狠高调
2楼-- · 2019-04-07 07:07

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.

查看更多
趁早两清
3楼-- · 2019-04-07 07:23

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

查看更多
登录 后发表回答