在类库(.NET标准)项目中添加install.ps1

问题描述:

我已将我的.NET Framework项目迁移到.NET标准项目。在类库(.NET标准)项目中添加install.ps1

在.NET Framework的项目,我有额外的文件配置一个.nuspec文件,并以“NuGet.exe包”

<files> 
    <file src="Install.ps1" target="tools\Install.ps1" /> 
    </files 

在.NET标准的项目,我没有不再是一个创建NuGet包nuspec文件并切换到“msbuild -t:Pack”来创建nuget包。我尝试将install.ps1设置为(BuildAction = Content),但随后在日志“Issue:PowerShell file out side tools folder”中看到警告。在nupkg文件中,目录是“content \ tools \ Install.ps1”,我需要“tools \ Install.ps1”。

+1

此问题的任何更新?你能从答案中得到任何有用的信息吗?如果没有,请让我知道这个问题的最新状态。 –

+0

对不起没有更新,我的临时解决方案是在创建后添加工具文件夹7zip –

+0

@ Leo-MSFT不知道您是否在添加新答案时收到通知,但我添加了适用于我的解决方案(并且似乎做的方式) – Robba

获取文件到一个包中的不同的路径,你可以在<Content>元素像这样使用<PackagePath>元素:

<ItemGroup> 
    <Content Include="install.ps1"> 
     <PackagePath>tools\</PackagePath> 
    </Content> 
</ItemGroup> 

(提供install.ps1是在你的项目的根,否则你将不得不调整Include属性值)

欲了解更多信息,请查阅文档有关pack的MSBuild目标位置:

https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target

我已尝试将install.ps1设置为(BuildAction = Content),但随后在日志“Issue:PowerShell file out side tools folder”中看到警告。而在nupkg文件的目录是“内容\ TOOLS \ Install.ps1”我需要“TOOLS \ Install.ps1”

当您使用msbuild -t:Pack创建NuGet包,的MSBuild/VS预计该文件是在内容文件夹中。但是,如果您仍然想要tools目录中的install.ps1文件,仍然可以使用.nuspec文件和nuget.exe打包该软件包。

具体步骤收拾包:

创建.nuspec如下设置:

<?xml version="1.0"?> 
<package > 
    <metadata> 
    <id>TestInstall.ps1</id> 
    <version>1.0.0</version> 
    <authors>Test</authors> 
    <owners>Test</owners> 
    <requireLicenseAcceptance>false</requireLicenseAcceptance> 
    <description>Package description</description> 
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> 
    <copyright>Copyright 2017</copyright> 
    <tags>Tag1 Tag2</tags> 
    </metadata> 

    <files> 
    <file src="Install.ps1" target="tools" /> 
    <file src="bin\Debug\netstandard1.4\TestInstall.ps1.dll" target="lib\netstandard1.4" /> 
    </files> 

</package> 

然后使用命令行:nuget.exe pack xxx.nuspec收拾的包,你会得到包Install.ps1在工具目录中:

enter image description here