【问题标题】:Add install.ps1 on Class Library (.NET Standard) Project在类库(.NET 标准)项目上添加 install.ps1
【发布时间】:2017-09-13 03:49:32
【问题描述】:

我已将 .NET Framework 项目迁移到 .NET Standard 项目。

在 .NET Framework 项目中,我有一个带有附加文件配置的 .nuspec 文件,并使用“NuGet.exe 包”创建 nuget 包

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

在 .NET Standard 项目中,我不再有 nuspec 文件并切换到“msbuild -t:Pack”来创建 nuget 包。我尝试将 install.ps1 设置为 (BuildAction = Content),但随后我在日志“问题:PowerShell 文件输出侧工具文件夹”中看到警告。在 nupkg 文件中,目录是“content\tools\Install.ps1”,我需要“tools\Install.ps1”。

【问题讨论】:

  • 这个问题有什么更新吗?你能从答案中得到任何有用的信息吗?如果没有,请告诉我这个问题的最新状态。
  • 抱歉没有更新,我的临时解决方案是使用 7zip 创建后添加工具文件夹
  • @Leo-MSFT 不确定您是否在添加新答案时收到通知,但我添加了一个适合我的解决方案(并且似乎是这样做的方法)
  • 你有这个问题的新更新吗?

标签: powershell nuget visual-studio-2017


【解决方案1】:

要将文件放入包中的不同路径,您可以使用 &lt;Content&gt; 元素中的 &lt;PackagePath&gt; 元素,如下所示:

<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

【讨论】:

    【解决方案2】:

    我尝试将 install.ps1 设置为 (BuildAction = Content),但随后我在日志“问题:PowerShell 文件输出端工具文件夹”中看到警告。在 nupkg 文件中,目录是“content\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打包包,你会得到tools目录下Install.ps1的包:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      • 1970-01-01
      • 2017-08-13
      • 2018-02-17
      • 1970-01-01
      相关资源
      最近更新 更多