How to “dotnet pack” an already compiled project

笑着哭i 提交于 2020-05-27 07:47:39

问题


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

  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

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

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.

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

Here is a sample of my build script

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

According to the 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."

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


回答1:


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.

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\

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



来源:https://stackoverflow.com/questions/50232375/how-to-dotnet-pack-an-already-compiled-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!