我有一个 nuget 包,它添加了一个我需要在每次构建项目后运行的可执行文件。
我可以通过向每个项目文件添加一个部分来手动添加它,如下所示:
<Target Name="AfterBuild">
<PropertyGroup>
<PathToOutputExe>..\bin\Executable.exe</PathToOutputExe>
<PathToOutputJs>"$(MSBuildProjectDirectory)\Scripts\Output.js"</PathToOutputJs>
<DirectoryOfAssemblies>"$(MSBuildProjectDirectory)\bin\"</DirectoryOfAssemblies>
</PropertyGroup>
<AspNetCompiler Condition="'$(MvcBuildViews)'=='true'" VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
<Exec Command="$(PathToOutputExe) $(PathToOutputJs) $(DirectoryOfAssemblies)" />
</Target>
安装 nuget 包时如何将其添加到项目中? (即在 Install.ps1 文件中使用 DTE $project 对象)
我将不胜感激对此的任何帮助。
谢谢
理查德
最佳答案
截至 NuGet 2.5 ,按照惯例,如果您在 build\{packageid}.targets
添加目标文件(注意“构建”与内容和工具处于同一级别),NuGet 会自动向项目中的 .targets 文件添加导入。那么你不需要在 install.ps1 中处理任何事情。卸载时将自动删除导入。
此外,我认为推荐的方法是创建一个单独的目标,该目标配置为在标准的“构建”目标之后运行:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="NuGetCustomTarget" AfterTargets="Build">
<PropertyGroup>
<PathToOutputExe>..\bin\Executable.exe</PathToOutputExe>
<PathToOutputJs>"$(MSBuildProjectDirectory)\Scripts\Output.js"</PathToOutputJs>
<DirectoryOfAssemblies>"$(MSBuildProjectDirectory)\bin\"</DirectoryOfAssemblies>
</PropertyGroup>
<AspNetCompiler Condition="'$(MvcBuildViews)'=='true'" VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
<Exec Command="$(PathToOutputExe) $(PathToOutputJs) $(DirectoryOfAssemblies)" />
</Target>
</Project>
关于powershell - 安装 NuGet 包时如何向项目添加 AfterBuild 事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8095855/