NuGet:如何使用 Install.ps1 文件更改文件的属性? [英] NuGet: How can I change property of files with Install.ps1 file?
问题描述
我正在创建 NuGet 包,为此我创建了 Nuspec 清单文件.在 content
文件夹中,我有两个文件,test.exe
和 test.config
.现在,当任何用户安装此包时,我想将这些文件的属性复制到输出目录"更改为始终复制".
I am creating NuGet package and for that I have created Nuspec manifest file. In content
folder I have two files, test.exe
and test.config
. Now I would like to change property "Copy To Output Directory" of these the files to "Copy Always" in project, when any user installs this package.
我发现了相关问题 NuGet 如何将属性应用于文件,显示可以使用 PowerShell install.ps1
脚本执行此操作,但我不知道如何创建该文件.
I found related question NuGet how to apply properties to files, that shows can do this using PowerShell install.ps1
script, but I have no idea how to create that file.
推荐答案
您的 install.ps1 文件应该如下所示.
Your install.ps1 file should look something like this.
param($installPath, $toolsPath, $package, $project)
$file1 = $project.ProjectItems.Item("test.exe")
$file2 = $project.ProjectItems.Item("test.config")
# set 'Copy To Output Directory' to 'Copy if newer'
$copyToOutput1 = $file1.Properties.Item("CopyToOutputDirectory")
$copyToOutput1.Value = 2
$copyToOutput2 = $file2.Properties.Item("CopyToOutputDirectory")
$copyToOutput2.Value = 2
这篇关于NuGet:如何使用 Install.ps1 文件更改文件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!