I have a special use-case where I need to be able to build a clean repository when I'm offline. I'm allowed to attach a local nuget feed and have a standard docker image locally available.
The build container is based on linux.
The solution I'm looking at involves preparing the local nuget feed with a dotnet restore, and then inside the linux container perform dotnet build with a specified nuget source.
I am building for the win-x64 runtime.
Environment:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.302
Commit: 41faccf259
Runtime Environment:
OS Name: alpine
OS Version: 3.12
OS Platform: Linux
RID: linux-musl-x64
Base Path: /usr/share/dotnet/sdk/3.1.302/
Host (useful for support):
Version: 3.1.6
Commit: 3acd9b0cd1
.NET Core SDKs installed:
3.1.302 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Expected result:
A successful build inside the docker linux container.
Actual result:
error NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): local
Steps to reproduce:
- On development machine (Win10 1909, with dotnet SDK 3.1.302):
mkdir dotnetTest
cd dotnetTest
dotnet new console
dotnet restore --runtime win-x64 --packages $pwd\nuget
- At this point the nuget folder contains the following (since this is only a minimal example):
microsoft.aspnetcore.app.runtime.win-x64
microsoft.netcore.app.runtime.win-x64
microsoft.windowsdesktop.app.runtime.win-x64
docker run --rm -it -v $pwd`:/repo -v $pwd\nuget`:/nuget mcr.microsoft.com/dotnet/core/sdk:3.1.302-alpine3.12
- Inside docker container:
dotnet nuget disable source nuget.org
dotnet nuget add source /nuget --name local
cd repo
dotnet build --runtime win-x64
The last command results in this:
Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
/repo/dotnetTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): local
Failed to restore /repo/dotnetTest.csproj (in 988 ms).
Build FAILED.
/repo/dotnetTest.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): local
0 Warning(s)
1 Error(s)
The interresting part highlighted: error NU1101: Unable to find package Microsoft.NETCore.App.Host.win-x64. No packages exist with this id in source(s): local
I should also mention that starting a new container and just running cd repo
followed by dotnet build --runtime win-x64
works without issues (the missing Microsoft.NETCore.App.Host.win-x64
is apperantly downloaded).
Tested workaround:
I have tried to use the "-p:DisableImplicitNuGetFallbackFolder=true"
when doing dotnet restore on the developer machine:
dotnet restore --runtime win-x64 --packages $pwd\nuget "-p:DisableImplicitNuGetFallbackFolder=true"
.
No difference in the result in this case.
Possible workaround:
Prepare the local nuget feed from within a (another) docker container instead of directly on the development computer. This is however extra complicated and should be avoided if not needed (it may be needed?).
Questions:
- Should it be possible to build a win-x64 console app from Linux with a local nuget feed prepared from a Windows machine (my approach above)?
- Any other workarounds or guideance to accomplish what I try to do?