我正在尝试为dotnet core 2.0项目设计一个生成脚本,该脚本执行以下操作
因为我知道源代码已在步骤1-3中构建和测试,所以我不想为nuget包重建代码,所以我指定--no-build和--no-restore
我遇到的困难是,在创建软件包时,因为我没有构建,并且输出目录设置为bin\Publish-pack命令正在bin\Debug目录中寻找项目。
有没有一种方法可以设置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
选项将尝试使用以前构建的输出,但是找不到,因为您是在非标准输出路径上构建的,而pack逻辑需要在生成的输出中定位一些生成的 Assets 。-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输出目录中
关于.net - 如何 “dotnet pack”一个已经编译的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50232375/