VS2017在nuget包中将'Build Action'设置为'Content' [英] VS2017 set 'Build Action' to 'Content' in a nuget package
问题描述
我使用以下命令行在gitlab
中创建我的nuget
软件包.
I create my nuget
packages in gitlab
with the following command line.
nuget pack -Prop Configuration=Release -OutputDirectory nuget %REPONAME%\%APPNAME%\%APPNAME%.csproj
如果我将Build Action
声明为Content
,将Copy To Output Directory
声明为Always
,则它不会应用在nuget软件包中,或者在安装时不会应用.
If I declare Build Action
to Content
and Copy To Output Directory
to Always
, it is not applied in the nuget package or rather when I install it.
我对这里的答案有些困惑: 将内容文件设置为复制本地:始终" ;在nuget包中
I'm a little bit confused about the answers here: Set content files to "copy local : always" in a nuget package
我没有* .nuspec文件.它是由上面的命令自动生成的.
I don't have a *.nuspec file. It is automatically generated by the command above.
- 我已经在
tools/*
中的解决方案中声明了 Install.ps1 文件
- 我想将 Install.ps1 脚本的
tools
文件夹自动包括在nuget软件包中,该脚本在安装时被调用
- I have declared a Install.ps1 file in my solution in
tools/*
- I want to automatically include the
tools
folder with the Install.ps1 script into the nuget package, that this script is invoked on install
Install.ps1脚本
param($installPath, $toolsPath, $package, $project)
$configItem = $project.ProjectItems.Item("snap7.dll")
# set 'Copy To Output Directory' to 'Always'
# 0 = Never
# 1 = Always
# 2 = PreserveNewestFile
$copyToOutput = $configItem.Properties.Item("CopyToOutputDirectory")
$copyToOutput.Value = 1
# set 'Build Action' to 'Content'
# 0 = None
# 1 = Compile
# 2 = Content
# 3 = EmbeddedResource
$buildAction = $configItem.Properties.Item("BuildAction")
$buildAction.Value = 2
推荐答案
要自动将文件/文件夹添加到nuget包中,我编写了一个名为NuGetLib
的小工具.
To automatically add files/folders to a nuget package, I have written a little tool called NuGetLib
.
全局变量是在安装程序中自动设置的.
The global variables are automatically set in the installer.
在我的.gitlab-ci.yml
中,仅需以下4行即可构建具有所有依赖项和tools文件夹的nuget软件包:
In my .gitlab-ci.yml
only these 4 lines are needed to build the nuget package with all dependencies and the tools folder:
# create output directory
- mkdir nuget
# create nuget package
- nuget pack -Prop Configuration=Release -OutputDirectory nuget %REPONAME%\%APPNAME%\%APPNAME%.csproj
# Add tools folder
- nugetlib add -t nuget -f .\%REPONAME%\%APPNAME%\tools
# deploy package to local repo
- xcopy /s /y /i nuget %NUGET_PATH%
您可以在此处下载: https://github.com/dojo90/nugetLib/releases
这篇关于VS2017在nuget包中将'Build Action'设置为'Content'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!