如何升级 NuGet 包中包含的 *.props?
How do you upgrade the *.props included in a NuGet package?
我正在开发一个添加预构建事件的内部 NuGet 包。
它通过指定包含每个 documentation 文件的构建文件夹来实现。
道具文件的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PreBuildEvent>Some commands go here</PreBuildEvent>
</PropertyGroup>
</Project>
如果项目从未有过预构建事件,则创建该事件。但是,如果 csproj 文件中存在现有的 PerBuildEvent 元素,则不会填充新值。如果我打开 csproj 文件并手动删除适当的 PropertyGroupElement:
,我可以让它工作
<PropertyGroup>
<PreBuildEvent>Some command line stuff</PreBuildEvent>
</PropertyGroup>
但是,我必须从那里删除 if,因为只是删除 UI 中预构建事件的内容不允许写入新值。
我想在安装中使用基于约定的方法来完成此操作。ps1 因为 documentation 指定:
[NuGet 3.x] This script will not be executed in projects managed by project.json
...并且(我之前省略了这部分)在没有 csproj 文件的情况下有没有办法做到这一点?
怎么回事?
我建议您不要在 .props 中使用预构建事件,因为我希望您不想覆盖项目中的现有事件。
相反,您可以考虑使用另一个目标,以便您的逻辑 运行 在构建之前使用 BeforeTargets:
<Target Name="MyBeforeBuild" BeforeTargets="Build">
<Message Text="### MyBeforeBuild ###" Importance="high" />
</Target>
如果您需要将预构建事件 运行 放在其他目标之后,您可能还想查看使用 DependsOnTargets 属性。
<Target Name="MyTarget" DependsOnTargets="$(CoreCompileDependsOn)">
</Target>
我正在开发一个添加预构建事件的内部 NuGet 包。
它通过指定包含每个 documentation 文件的构建文件夹来实现。
道具文件的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PreBuildEvent>Some commands go here</PreBuildEvent>
</PropertyGroup>
</Project>
如果项目从未有过预构建事件,则创建该事件。但是,如果 csproj 文件中存在现有的 PerBuildEvent 元素,则不会填充新值。如果我打开 csproj 文件并手动删除适当的 PropertyGroupElement:
,我可以让它工作<PropertyGroup>
<PreBuildEvent>Some command line stuff</PreBuildEvent>
</PropertyGroup>
但是,我必须从那里删除 if,因为只是删除 UI 中预构建事件的内容不允许写入新值。
我想在安装中使用基于约定的方法来完成此操作。ps1 因为 documentation 指定:
[NuGet 3.x] This script will not be executed in projects managed by project.json
...并且(我之前省略了这部分)在没有 csproj 文件的情况下有没有办法做到这一点?
怎么回事?
我建议您不要在 .props 中使用预构建事件,因为我希望您不想覆盖项目中的现有事件。
相反,您可以考虑使用另一个目标,以便您的逻辑 运行 在构建之前使用 BeforeTargets:
<Target Name="MyBeforeBuild" BeforeTargets="Build">
<Message Text="### MyBeforeBuild ###" Importance="high" />
</Target>
如果您需要将预构建事件 运行 放在其他目标之后,您可能还想查看使用 DependsOnTargets 属性。
<Target Name="MyTarget" DependsOnTargets="$(CoreCompileDependsOn)">
</Target>