Azure DevOps / Pipelines:设置 NuGet 包中内容文件的“构建操作”和“复制到输出目录”属性
Azure DevOps / Pipelines: Set the “Build Action” and “Copy To Output Directory” properties of a content file in a NuGet package
我正在创建一个 .net Standard 2.0 NuGet 包,我想部署一个配置文件并将此文件标记为“内容”和“如果较新则复制”。
当我安装包时,配置文件部署在项目的根目录下,但属性设置为默认值:“None”和“不复制”。
我试图在 azure 管道中使用内联 powershell 脚本解决问题:
- powershell: |
$project= Get-Project Foo
$project.ProjectItems.Item("foo.config").Properties.Item("CopyToOutputDirectory").Value = 2
$project.ProjectItems.Item("foo.config").Properties.Item("BuildAction").Value = 2
但我收到以下错误:
Get-Project : The term 'Get-Project' is not recognized as the name of
a cmdlet, function, script file, or operable program...
有没有办法在管道任务中设置这些属性?
正如Get-Project document中所说:
Get-Project command Available only within the Package Manager Console in Visual Studio on Windows.
作为解决方法,您可以手动编辑项目的 .csproj 文件以包含配置文件。请参见下面的示例。在您的 .csproj 文件中添加以下行:
<ItemGroup>
<Content Include="content.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
更新:
内容文件位于我的 repo 文件夹的根目录中。
我在 csproj 文件中手动添加了以下行。
content.config文件复制成功:
解决:与管道无关。我只需要在 csproj 文件中将 PackageCopyToOutput 属性 设置为 true:
<ItemGroup>
<Content Include="foo.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>
我正在创建一个 .net Standard 2.0 NuGet 包,我想部署一个配置文件并将此文件标记为“内容”和“如果较新则复制”。 当我安装包时,配置文件部署在项目的根目录下,但属性设置为默认值:“None”和“不复制”。 我试图在 azure 管道中使用内联 powershell 脚本解决问题:
- powershell: |
$project= Get-Project Foo
$project.ProjectItems.Item("foo.config").Properties.Item("CopyToOutputDirectory").Value = 2
$project.ProjectItems.Item("foo.config").Properties.Item("BuildAction").Value = 2
但我收到以下错误:
Get-Project : The term 'Get-Project' is not recognized as the name of a cmdlet, function, script file, or operable program...
有没有办法在管道任务中设置这些属性?
正如Get-Project document中所说:
Get-Project command Available only within the Package Manager Console in Visual Studio on Windows.
作为解决方法,您可以手动编辑项目的 .csproj 文件以包含配置文件。请参见下面的示例。在您的 .csproj 文件中添加以下行:
<ItemGroup>
<Content Include="content.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
更新:
内容文件位于我的 repo 文件夹的根目录中。
我在 csproj 文件中手动添加了以下行。
content.config文件复制成功:
解决:与管道无关。我只需要在 csproj 文件中将 PackageCopyToOutput 属性 设置为 true:
<ItemGroup>
<Content Include="foo.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<PackageCopyToOutput>true</PackageCopyToOutput>
</Content>
</ItemGroup>