如何 "dotnet pack" 一个已经编译好的项目
How to "dotnet pack" an already compiled project
我正在尝试为执行以下操作的 dotnet core 2.0 项目设计构建脚本
- 清理输出目录
- 使用-o构建解决方案bin\Publish
- 使用 dotnet vstest 运行单元测试
- 使用 dotnet pack 创建一个 Nuget 包
因为我知道源代码已经在步骤 1-3 中构建和测试,我不想为 nuget 包重建我的代码,所以我指定了 --no-build 和 --no-restore
我遇到的困难是在创建包时,因为我没有构建并且输出目录设置为 bin\Publish - pack 命令正在寻找 [=42= 中的项目]目录。
有没有办法可以将 dotnet pack 命令设置为知道在哪里寻找已编译的对象?
这是我的构建脚本示例
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
根据Microsoft Docs on dotnet pack
"By default, dotnet pack builds the project first. If you wish to
avoid this behavior, pass the --no-build option. This is often useful
in Continuous Integration (CI) build scenarios where you know the code
was previously built."
所以我希望这是可能的,但我遗漏了一些明显的东西。任何帮助将不胜感激。
原因是dotnet pack --no-build
选项会尝试使用之前构建的输出,但是找不到,因为你构建的是非标准输出路径,打包逻辑需要定位一些资产生成到构建输出中。
-o
选项对于 pack
和 build
命令在内部是不同的,但您可以将 pack 命令更改为:
dotnet pack --no-build --no-restore ..\MySolution.ConsoleApp\MySolution.csproj -o bin\Publish\Nuget\ /p:OutputPath=bin\Publish\
这将使用 bin\Publish
目录中内置的输出并将其放入 bin\Publish\Nuget\
中的 Nuget 输出目录
我正在尝试为执行以下操作的 dotnet core 2.0 项目设计构建脚本
- 清理输出目录
- 使用-o构建解决方案bin\Publish
- 使用 dotnet vstest 运行单元测试
- 使用 dotnet pack 创建一个 Nuget 包
因为我知道源代码已经在步骤 1-3 中构建和测试,我不想为 nuget 包重建我的代码,所以我指定了 --no-build 和 --no-restore
我遇到的困难是在创建包时,因为我没有构建并且输出目录设置为 bin\Publish - pack 命令正在寻找 [=42= 中的项目]目录。
有没有办法可以将 dotnet pack 命令设置为知道在哪里寻找已编译的对象?
这是我的构建脚本示例
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
根据Microsoft Docs on dotnet pack
"By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built."
所以我希望这是可能的,但我遗漏了一些明显的东西。任何帮助将不胜感激。
原因是dotnet pack --no-build
选项会尝试使用之前构建的输出,但是找不到,因为你构建的是非标准输出路径,打包逻辑需要定位一些资产生成到构建输出中。
-o
选项对于 pack
和 build
命令在内部是不同的,但您可以将 pack 命令更改为:
dotnet pack --no-build --no-restore ..\MySolution.ConsoleApp\MySolution.csproj -o bin\Publish\Nuget\ /p:OutputPath=bin\Publish\
这将使用 bin\Publish
目录中内置的输出并将其放入 bin\Publish\Nuget\