4

我负责在我们公司发布的一个库作为 NuGet 包,我按照“添加自述文件和其他文件”指南显示一个 readme.txt,其中包含用户在使用 Visual Studio 时安装或更新包时的重要更改。这有效 - 即当您安装软件包时,会显示 readme.txt。但是,当您安装软件包时,此 readme.txt 文件也将被复制到目标项目的根目录中。

有谁知道我可以如何阻止它(即安装时显示 readme.txt,但不要将其添加到目标项目中)?用户查看此文件非常有用,但如果将其添加到项目中会令人困惑。

库的 .nuspec 如下所示:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <projectUrl>http://example.com/blah/blah</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
  </metadata>
  <files>
    <file src="README.txt" target="" />
  </files>
</package>

打包 + 推送通常由 TeamCity 构建步骤执行,但如果我使用以下命令行构建 pkg,则会出现相同的行为:

$ nuget pack MyLibrary.csproj
$ nuget push MyLibrary-{version}.nupkg -source {internal-nuget-server}
4

2 回答 2

6

这里的问题是我在文件中README.txt包含了它应该在什么时候使用- 抱歉,这有点像红鲱鱼,因为我没有在我的问题中包含这些信息!.csproj<Content include...><None include...>

于 2018-03-08T11:40:13.340 回答
0

有谁知道我怎么能阻止这个

要解决此问题,请确保您将.nuspec文件打包,并且该部分中的README.txt文件不是针对. 以下是我的测试步骤:<files> content

  1. 创建一个测试样本项目“ TestReadmeFile

  2. 在与命令.nupsec相同的文件夹中创建文件,然后定义替换标记($id$、$version$ 等)TestReadmeFile.csprojnuget.exe spec "TestReadmeFile.csproj"

  3. 在 nuspec 文件中添加一个部分,仅包含 readme.txt,如下所示:<file src="readme.txt" target="" />

以下是我的 .nuspec 文件:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>TestReadmeFile</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
  <files>
    <file src="bin\Debug\TestReadmeFile.dll" target="lib\net462" />
    <file src="README.txt" target="" />
  </files>
</package>
  1. 通过命令行打包 .nuspec:nuget.exe pack "TestReadmeFile.csproj.nuspec"

创建该包后,该包将自动打开 readme.txt ,而不会将其添加到目标项目中。

于 2018-02-19T14:46:27.630 回答