I'm trying to design a build script for a dotnet core 2.0 project that does the following actions
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.
By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.
You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new , dotnet build , dotnet run , dotnet test , dotnet publish , and dotnet pack . To disable implicit restore, use the --no-restore option.
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\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With