本文介绍了如何“ dotnet pack”一个已经编译的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为dotnet core 2.0项目设计一个生成脚本,该脚本执行以下操作

I'm trying to design a build script for a dotnet core 2.0 project that does the following actions


  1. 清理输出目录
  2. 使用-o bin\Publish
  3. 构建解决方案
  4. 使用dotnet vstest运行单元测试

  5. 创建Nuget包使用dotnet pack

  1. Cleans output directories
  2. Builds Solution with -o bin\Publish
  3. Runs Unit Tests with dotnet vstest
  4. Creates a Nuget package with dotnet pack

因为我知道源代码已经在步骤1-3中构建并测试过,所以我不想重建我的代码对于nuget软件包,所以我要指定--no-build和--no-restore

Because I know the source code has been built and tested in steps 1-3 I do not want to rebuild my code for the nuget package, so I am specifying --no-build and --no-restore

我遇到的困难是创建软件包时,因为我不在构建中,输出目录设置为bin\Publish-pack命令在bin\Debug目录中查找项目。

The difficulty I'm having is that when creating the package, because I am not building and the output directory is set to be bin\Publish - the pack command is looking for items in the bin\Debug directory.

有没有办法我可以将dotnet pack命令设置为知道在哪里查找已编译的对象?

Is there a way I can set the dotnet pack command to know where to look for the already compiled objects?

这是我的构建脚本示例

dotnet clean ..\MySolution.sln -o bin/Publish/
dotnet build ..\MySolution.sln /p:Configuration=Release -o bin/Publish/
dotnet vstest ..\MySolution.UnitTests\bin\Publish\MySolution.UnitTests.dll
dotnet pack --no-build --no-restore ..\MySolution.ConsoleApp\MySolution.csproj -o bin\Publish\Nuget\

....

error : The file 'D:\MySolution.ConsoleApp\bin\Debug\netcoreapp2.0\MySolution.ConsoleApp.runtimeconfig.json' to be packed was not found on disk

根据

所以我希望这是可能的,并且我遗漏了一些显而易见的东西。我们将不胜感激。

So I'm hoping that this is possible and I'm missing something obvious. Any help would be appreciated.

推荐答案

这是因为 dotnet pack --no-build 选项将尝试使用以前构建的输出,但是由于您将其构建为非输出而找不到它-standard输出路径和打包逻辑需要定位生成到生成输出中的某些资产。

The reason for this is that the dotnet pack --no-build option will try to use the previously built output, but can't find it since you built to a non-standard output path and the pack logic needs to locate some assets generated into the build output.

-o pack build 命令的内部选项不同,但是您可以将pack命令更改为:

The -o options are internally different for the pack and build commands but you can change the pack command to:

dotnet pack --no-build --no-restore ..\MySolution.ConsoleApp\MySolution.csproj -o bin\Publish\Nuget\ /p:OutputPath=bin\Publish\

这将使用构建的输出放入 bin\Publish 目录并将其放在 bin\Publish\Nuget\

This will use the output built into the bin\Publish directory and put it into the Nuget output directory in bin\Publish\Nuget\

这篇关于如何“ dotnet pack”一个已经编译的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:53