【发布时间】:2017-08-16 05:13:41
【问题描述】:
This sample 展示了一个 .NET Core 项目,只需使用 dotnet pack 即可将其打包成 nuget 包,当在另一个项目中恢复时,它会集成到 msbuild 管道中。这个示例的一大优点是它创建了一个在 linux、mac 和 Windows 上与 msbuild 集成的 nuget 包。但是,自定义构建代码不依赖于任何其他程序集。
如何调整此示例以使用使用依赖项的代码?
这是我失败的尝试:
尝试 1
我添加了对 Newtonsoft.Json 的包引用并更改了代码以进行一些 JSON 序列化。但是,在使用 build nuget 的项目中,当我执行 dotnet publish 时,出现以下错误:
error MSB4018: The "Zip" task failed unexpectedly. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
此外,如果我的项目还没有对 JSON.NET 的依赖,添加构建 nuget 将不必要地添加它。
尝试 2
我使用nuget.exe spec 创建了一个.nuspec 文件。在文件末尾,我添加了:
<files>
<file src="bin\Release\**" target="build" />
<file src="build\**" target="build" />
</files>
但是,“dotnet pack”和“msbuild /t:pack”都会忽略该文件,并且nuget.exe pack 失败并出现错误Unable to find 'bin\Release\0-WriteATask\bin\Release\'. Make sure the project has been built.。
如果我尝试nuget.exe pack Zipper.nuspec 或msbuild /t:pack /p:NuspecFiles=Zipper.nuspec,它们都会失败并显示消息Value cannot be null or an empty string.。
尝试 3
我编辑了 nuspec 以删除通常从项目中计算的所有占位符(任何以 $ 开头和结尾的字符串)。然后,做了一个nuget.exe pack Zipper.nuspec创建了一个nupkg文件,net46文件夹包含Newtsonsoft.Json.dll,而netstandard1.3文件夹没有。
【问题讨论】: