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

问题描述

我正在尝试为执行以下操作的 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 binPublish 构建解决方案
  3. 使用 dotnet vstest 运行单元测试
  4. 使用 dotnet pack 创建 Nuget 包

因为我知道源代码已经在步骤 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

我遇到的困难是在创建包时,因为我没有构建并且输出目录设置为 binPublish - pack 命令正在 binDebug 目录中查找项目.

The difficulty I'm having is that when creating the package, because I am not building and the output directory is set to be binPublish - the pack command is looking for items in the binDebug 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.UnitTestsinPublishMySolution.UnitTests.dll
dotnet pack --no-build --no-restore ..MySolution.ConsoleAppMySolution.csproj -o binPublishNuget

....

error : The file 'D:MySolution.ConsoleAppinDebug
etcoreapp2.0MySolution.ConsoleApp.runtimeconfig.json' to be packed was not found on disk

根据 Microsoft Docs on dotnet pack

"默认情况下,dotnet pack 会先构建项目.如果您希望避免这种行为,传递 --no-build 选项.这通常很有用在您知道代码的持续集成 (CI) 构建场景中以前建造的."

所以我希望这是可能的,但我遗漏了一些明显的东西.任何帮助将不胜感激.

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

推荐答案

这样做的原因是 dotnet pack --no-build 选项将尝试使用之前构建的输出,但可以找不到它,因为您构建到非标准输出路径,并且打包逻辑需要定位生成到构建输出中的一些资产.

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 选项对于 packbuild 命令在内部是不同的,但您可以将 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.ConsoleAppMySolution.csproj -o binPublishNuget /p:OutputPath=binPublish

这将使用 binPublish 目录中内置的输出并将其放入 binPublishNuget

This will use the output built into the binPublish directory and put it into the Nuget output directory in binPublishNuget

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

07-30 04:44