使用 nuget 包添加自定义构建步骤 [英] Adding a custom build step with a nuget package

查看:66
本文介绍了使用 nuget 包添加自定义构建步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 nuget 包,它将设置当前项目以使用我公司的程序集版本控制标准.除了添加自定义构建步骤之外,我已经完成了我想做的所有事情(到目前为止).

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.

过去,这是通过直接编辑 .csproj 文件并将几个新标签添加到 xml 中手动完成的.这些是...

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 ...

  • 属性组
  • 目标

它实际上成功地添加了它们,但我是通过编辑 xml 而不是通过 install.ps1$project 参数中的 EnvDTE 对象来完成的.但是我收到一条消息,询问我是否要放弃我的更改.

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.

在我进行更改之前,我已经将 $project.Save() 添加到我的脚本中,这消除了弹出窗口,我只是得到一个告诉我项目已更改的人问我是否要重新加载它.哪个更好,但仍然不够完美.

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?

推荐答案

您还可以使用 David Fowler(NuGet 首席开发人员)编写的 NuGetPowerTools 包.

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

Install-Package NuGetPowerTools

将其作为依赖添加到您的包中,然后在 install.ps1 脚本中,您可以调用:

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

查看 https://github.com/davidfowl/NuGetPowerTools 中的代码以了解更多信息.

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

这篇关于使用 nuget 包添加自定义构建步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆