visual-studio - 使用 Visual Studio 包在 nuget 包中包含构建目录

标签 visual-studio msbuild nuget

我正在尝试使用内置的 nuget 包构建在 Visual Studio 中创建一个 nupkg,并将我的项目中的构建目录包含在 nupkg 中。看起来这应该是一项相当简单的任务,但我无法让它工作。从我的谷歌搜索中,将其中任何一个添加到我的 csproj 文件应该可以工作,但两者都在 nupkg 中创建一个空的“build”目录:

 <ItemGroup>
    <None Include="build\**">
      <Pack>true</Pack>
      <PackagePath>build\</PackagePath>
      <IncludeInPackage>true</IncludeInPackage>
    </None>
  </ItemGroup>

使用 nuget pack在我的 nuspec 中使用以下内容创建包确实有效:
  <files>
        <!-- Include everything in \build -->
    <file src="build\**" target="build" />
  </files>

最佳答案

Include build directory in nuget package using visual studio pack



根据文档Including content in a package ,您应该使用属性 <Pack>true</Pack><PackagePath>build\</PackagePath> :

If you want to copy all your content to only a specific root folder(s) (instead of content and contentFiles both), you can use the MSBuild property ContentTargetFolders, which defaults to "content;contentFiles" but can be set to any other folder names.

PackagePath can be a semicolon-delimited set of target paths. Specifying an empty package path would add the file to the root of the package.



因此,您可以像下面这样更改您的 ItemGroup:
  <ItemGroup>
    <None Include="build\**" Pack="True" PackagePath="build\" />
  </ItemGroup>

更新:

I believe this is the same as what I added but in a different XML structure and without the Pack attribute


Pack属性是关键。它适用于您的 XML 结构和 Pack 属性。您应该确保您在 中拥有这些文件。构建 中的文件夹您的项目文件夹 :

enter image description here

在下面检查我的测试演示:

enter image description here

更新 2:

啊!您正在使用 .net framework项目!!这就是这个问题的原因。此方法用于.net standard.net core项目默认情况下,它不适用于 .net framework .要解决此问题,您必须使用 .nupsec文件,就像你在问题中发帖一样。

如果您仍想在 nuget 包中包含构建目录 使用 Visual Studio 包 ,您需要将项目类型更改为 SDK 类型:

查询 this document了解更多详情。

然后就可以使用我们之前讲过的方法了。

希望这可以帮助。

关于visual-studio - 使用 Visual Studio 包在 nuget 包中包含构建目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53281775/

相关文章:

visual-studio - 在构建时运行 Visual Studio 自定义工具

c# - MvcBuildViews 忽略 ascx 和 aspx,只编译 cshtml

visual-studio-2010 - 尝试使用 ServiceController 时出现错误 MSB4062

msbuild - 从 VSO 构建到 Azure 网站时排除文件夹

c# - 冲突的 Newtonsoft.Json nuget 版本。

nuget - 指定 Octopack nuget 包文件的目标路径

c# - 在 Visual Studio Code 中模仿 Visual Studio IntelliSense 过滤行为?

c# Visual Studio ...以编程方式添加引用

c# - 如何设置几个visual C#项目的输出路径

nuget - 通过 NuGet 的 Azure 存储模拟器?