I'm constructing a docker container from a Dotnet Core 2.0 WebApp that was packaged with dotnet publish, but publishing this way doesn't copy the extensions in Microsoft.EntityFrameworkCore.Tools.DotNet that enable the dotnet-ef command.
Specifically, I want to run dotnet ef commands in the container, but I get this error:
No executable found matching command "dotnet-ef"
My .csproj file contains this, so dotnet-ef works fine on the host:
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
Is there a way to run migrations from a dotnet app that's been packaged with dotnet publish?
Based on #bricelam's suggestion and Ben Day's blog entry, this works for dotnet 2.x on Linux:
$ dotnet exec \
--depsfile Api.deps.json \
/usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.entityframeworkcore.tools.dotnet/2.0.2/tools/netcoreapp2.0/ef.dll \
database update \
--assembly ./MyDllWithMigrations.dll \
--startup-assembly Api.dll \
--project-dir . \
--verbose
(This is based on the microsoft/aspnetcore-build base image.)
Related
We are using Azure DevOps pipelines. We have a step that publishes the our private nuget package to the Azure Artifacts. However, the build breaks at other steps because the nuget package (that was published on previous steps) is not found. The strange thing is that after the package is published, I can see it in the package-manager console or on Visual Studio and even in the Artifacts in Azure DevOps. But for some reason, the pipeline doesn't find the package. After 30-50min, I re-run the pipeline and then it finds the package.
What could be happening to take so long time for the pipeline to find the my package?
Edit 1:
This is my yaml for the step with error
- script: |
pwd && ls -la
dotnet restore "$(solution_path)" $(nuget_args)
dotnet publish -c Release -o $(System.DefaultWorkingDirectory)/bin "$(main_project_path)"
mkdir artifact
cp -r $(System.DefaultWorkingDirectory)/bin artifact/bin
displayName: Build Application
The error is:
/data/vstsagent/user/389/s/src/MyProject.csproj
: error NU1102: Unable to find package MyPackage with
version (>= 2.1.0) [/data/vstsagent/user/389/s/src/MySolution.sln]
/data/vstsagent/user/389/s/src/MyProject.csproj
: error NU1102: - Found 28 version(s) in MyPrivateRepository [ Nearest
version: 2.1.0-preview.6 ]
[/data/vstsagent/user/389/s/src/MySolution.sln]
It is not clear what feed is used by dotnet restore command.
Confirm that you have configured your custom nuget feed in nuget.config and using it.
Try adding "--verbose" switch in dotnet restore command and check if your feed is used for restoring packages.
Use the --no-cache option so dotnet restore doesn't use the local cache.
I try to publish a .net Core (WinForms) project, which I upgraded from core3.0 to net5.0, as Single Exe.
I get the following error:
NETSDK1142: Including symbols in a single file bundle is not supported when publishing for .NET5 or higher.
researching NETSDK1142 I do not get any results in google regarding a fix.
With Core3.0 the following command worked:
dotnet publish nameofproject.csproj \
-o bin/Release/core \
-c Release \
-p:Platform=x64 \
-r win-x64 \
--self-contained true
I also tried the following flags for net5.0. Still getting the same error even with DebugSymbols=false
dotnet publish nameofproject.csproj \
-o bin/Release/core \
-c Release \
-p:Platform=x64 \
-p:NoWarn=CS0618 \
-p:NoWarn=NU1605 \
--self-contained true \
-p:PublishSingleFile=true \
-p:IncludeAllContentForSelfExtract=true \
-p:PublishReadyToRun=true \
-p:PublishTrimmed=false \
-p:IncludeNativeLibrariesForSelfExtract=true \
/p:DebugType=None /p:DebugSymbols=false
Solution
just add -p:IncludeSymbolsInSingleFile=false or /p:IncludeSymbolsInSingleFile=false to the publish command
How I found it
After trying to fix the issue since 2 days the solution was found in the dotnet/sdk Source Code.
in sdk/src/Tasks/Common/Resources/Strings.resx I found the error string
<data name="CannotIncludeSymbolsInSingleFile" xml:space="preserve">
<value>NETSDK1142: Including symbols in a single file bundle is not supported when publishing for .NET5 or higher.</value>
<comment>{StrBegin="NETSDK1142: "}</comment>
</data>
then I tracked down the CannotIncludeSymbolsInSingleFile string resource in the sourcecode and found the following result in sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets
<NETSdkError Condition="'$(PublishSingleFile)' == 'true' And
'$(IncludeSymbolsInSingleFile)' == 'true' And
'$(_TargetFrameworkVersionWithoutV)' >= '5.0' And '$(TargetFrameworkIdentifier)' == '.NETCoreApp'"
ResourceName="CannotIncludeSymbolsInSingleFile" />
There I found the Flag I had to set on build IncludeSymbolsInSingleFile
I have a .NetCore 3.1 commandline app. When buidling locally and publishing, it works completely fine using below commandline
dotnet publish -c dev -r win-x64 --self-contained true
In the Azure pipeline - I had to do the dotnet restore before doing a publish using the above command. Whilst publishing I had to add extra param --no-restore, as per Microsoft's recommendation here as I have private nuget feeds.
dotnet publish -c dev -r win-x64 --self-contained true --no-restore
Most dotnet commands, including build, publish, and test include an
implicit restore step. This will fail against authenticated feeds,
even if you ran a successful dotnet restore in an earlier step,
because the earlier step will have cleaned up the credentials it used.
To fix this issue, add the --no-restore flag to the Arguments textbox.
Now, the publish part of the pipeline has started failing with the error -
C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'MyProject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
Am not using a publish xml, but specifying all the arguments as shown above in the command line. I've checked the csproj has the target framework specified
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
</PropertyGroup>
Need any pointers as to what might be going wrong here?
Thanks
Please add RuntimeIdentifier as mentioned in the error message:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Please also check PlatformTarget.
<PlatformTarget>AnyCPU</PlatformTarget>
I guess the local machine has a different OS than the build agent.
I'm trying to build my .NET Core 2.1 application from the command-line on my Jenkins server.
It builds fine on my local machine (Windows 10, Visual Studio 2017 Enterprise), and if I manually build it on the server Jenkins is running on (manually checkout Git repository and running dotnet build). It's only when I'm doing it through Jenkins in a Docker container that it fails.
The error:
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
The package exists in ~/.nuget/packages/.
I'm aware my Jenkinsfile is a bit weird at the moment, but that has to do with me trying to make this all work. It seems dotnet restore is working fine, but dotnet build is somehow not locating these files.
I've tried specifying the package directory (through the environment variable, with dotnet restore --sources and dotnet build --sources.
I attached pretty much anything I could think of at the moment, but if I forgot something please tell. I'm pretty lost at the moment.
My Jenkinsfile:
pipeline {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
}
}
environment {
HOME = '.'
NUGET_PACKAGES = './.nuget/packages/'
}
stages {
stage('pre-build') {
steps {
// logging tooling versions
sh 'dotnet --info'
sh 'find ~/.nuget/packages/microsoft.codequality.analyzers/ -type f'
sh 'dotnet nuget locals all --list'
sh 'dotnet restore'
// sh 'dotnet clean'
}
}
stage('build') {
steps {
// sh 'dotnet restore --force --no-cache'
// sh 'ls ./packages/'
// sh 'find ./packages/microsoft.codequality.analyzers/ -type f'
sh 'dotnet build --no-restore'
}
}
stage('test') {
steps {
sh 'no test project configured'
// sh 'dotnet test'
}
}
}
}
My .csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet></CodeAnalysisRuleSet>
<Features>IOperation</Features>
</PropertyGroup>
</Project>
Some build details:
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
Inside docker container:
$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.403
Commit: 04e15494b6
Runtime Environment:
OS Name: debian
OS Version: 9
OS Platform: Linux
RID: debian.9-arm
Base Path: /usr/share/dotnet/sdk/2.1.403/
Host (useful for support):
Version: 2.1.5
Commit: 290303f510
.NET Core SDKs installed:
2.1.403 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
$ find ./.nuget/packages/microsoft.codequality.analyzers/ -type f
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.VisualBasic.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/vb/Microsoft.CodeQuality.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/analyzers/dotnet/cs/Microsoft.CodeQuality.CSharp.Analyzers.dll
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/.signature.p7s
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/ThirdPartyNotices.rtf
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.CSharp.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.VisualBasic.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/build/Microsoft.CodeQuality.Analyzers.props
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/PerformanceRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/MaintainabilityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/UsageRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DocumentationRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/ReliabilityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDisabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/SecurityRulesEnabled.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/DesignRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/NamingRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/rulesets/AllRulesDefault.ruleset
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg.sha512
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.2.6.2.nupkg
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/microsoft.codequality.analyzers.nuspec
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/uninstall.ps1
./.nuget/packages/microsoft.codequality.analyzers/2.6.2/tools/install.ps1
$ dotnet nuget locals all --list
info : http-cache: ./.local/share/NuGet/v3-cache
info : global-packages: ./.nuget/packages/
info : temp: /tmp/NuGetScratch
info : plugins-cache: ./.local/share/NuGet/plugins-cache
$ dotnet restore
Restoring packages for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj...
Restore completed in 13.5 sec for /var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj.
$ dotnet build --no-restore
Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
Build FAILED.
/usr/share/dotnet/sdk/2.1.403/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1064: Package Microsoft.CodeQuality.Analyzers, version 2.6.2 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/var/lib/jenkins/jobs/pr-builder/jobs/cgi-api/branches/PR-18/workspace/API/API.csproj]
0 Warning(s)
1 Error(s)
I've resolved the issue by specifying where dotnet build should look for the NuGet packages. It that within the image it doesn't look at the right location (although I'm not sure where it is looking either...)
I've specified the location with the --packages option. This option is listed in the dotnet restore documentation, but not in the dotnet build ones, even though it is available there as well (and you need it there, specifically).
You can specify it as follows:
dotnet restore --packages <path>
and
dotnet build --packages <path>
It works with the --no-restore option as well, if you need that.
My final Jenkinsfile looks as follows:
pipeline {
agent {
docker {
image 'microsoft/dotnet:2.1-sdk'
}
}
environment {
HOME = '.'
}
stages {
stage('pre-build') {
steps {
// logging tooling versions
sh 'dotnet --info'
sh 'dotnet nuget locals all --list'
sh 'dotnet clean'
}
}
stage('build') {
steps {
sh 'dotnet build --packages ./.nuget/packages'
}
}
stage('test') {
steps {
sh 'echo no test project configured'
// sh 'dotnet test'
}
}
}
}
I ran into a similar issue solved by clearing global packages and cache with dotnet nuget locals all --clear as explained here.
I developed application in asp.net-core 2.0 preview1.
I developed on windows with Visual Studio 2017.
Now I want to deploy it to Linux server using Docker.
I created Docker file:
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 44305
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Aplication.dll"]
After that running commands:
dotnet build -o obj/Docker/publish -c Release
dotnet publish -o obj/Docker/publish -c Release
docker build -t testapi-api .
docker run -p 44305:80 --name api testapi-api
Afer the last command run I am getting next error:
An assembly specified in the application dependencies manifest (Aplication.deps.json) was not found:
package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.0-preview1-final'
path: 'lib/netcoreapp2.0/Microsoft.AspNetCore.Antiforgery.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
manifest.win7-x64.xml;manifest.win7-x86.xml;manifest.osx-x64.xml;manifest.linux-x64.xml
I am new with asp.net-core and especially with Docker. So any help with this is great.
You need to specify -r linux-x64 parameter in dotnet publish command like that:
dotnet publish -o obj/Docker/publish -c Release -r linux-x64
This will make a standalone deployment.
Try to use this image "2.0.0-preview1". Basically change the first line to FROM microsoft/aspnetcore:2.0.0-preview1, if your local has preview 1 dotnet core.
If it not works, check your local dotnet core version, it it points to 2.0.0-preview2-final, then change all your references pointing to 2.0.0-preview2-final in csproj file, then use the 2.0.0-preview2 image. It would help you I hope.