Reputation: 188
i have a problem with the way my app is published. I wan't to target the framework 5.0.0 but the publish command use the version 5.0.6. I think the 5.0.6 version is installed on my computer because it was a part of the visual studio installation (but i also have the 5.0.0 installed). I can't uninstall the 5.0.6 otherwise my visual studio stop working I see i can force the target framework with a global.json at the root of my project but it still doesn't work
{
"sdk": {
"version": "5.0.0" //i tried also 5.0.100
}
}
there is my publish profile
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>a9a4c861-924a-4190-bc23-fd99cf48edd2</ProjectGuid>
<publishUrl>bin\Release\net5.0-windows\publish</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<TargetFramework>net5.0-windows</TargetFramework>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishTrimmed>True</PublishTrimmed>
</PropertyGroup>
</Project>
I reference these framework : Microsoft.AspnetCore.App, Microsoft.NetCore.App, Microsoft.WindpwsDesktop.App.WindowsForms
i also reference these nuget packages
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
</ItemGroup>
the sdk installed on my machine
C:\WINDOWS\system32>dotnet --list-sdks
2.1.524 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.117 [C:\Program Files\dotnet\sdk]
3.1.411 [C:\Program Files\dotnet\sdk]
5.0.100-preview.8.20417.9 [C:\Program Files\dotnet\sdk]
5.0.100-rc.1.20452.10 [C:\Program Files\dotnet\sdk]
5.0.100-rc.2.20479.15 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
5.0.200-preview.20614.14 [C:\Program Files\dotnet\sdk]
5.0.400-preview.21328.4 [C:\Program Files\dotnet\sdk]
My visual studio version is the 2019 Community Version 16.11.0 Preview 3.0
When i publish, i can see these line in the output (hundred of them)
-a "obj\Release\net5.0-windows\win-x86\Is.Geckos.LocalService.dll"
-a "C:\Users\julie\.nuget\packages\microsoft.windowsdesktop.app.runtime.win-x86\5.0.6\runtimes\win-x86\lib\net5.0\Accessibility.dll"
-a "C:\Users\julie\.nuget\packages\microsoft.windowsdesktop.app.runtime.win-x86\5.0.6\runtimes\win-x86\lib\net5.0\Microsoft.VisualBasic.Forms.dll"
...
-reference "C:\Users\julie\.nuget\packages\microsoft.aspnetcore.app.runtime.win-x86\5.0.6\runtimes\win-x86\lib\net5.0\Microsoft.AspNetCore.Connections.Abstractions.dll"
the problem not concern uniquely the publish but also when i launch the app (Evironnemment.Version give me 5.0.6)
I think the global.json is not read at all because when i put unexpected characters in this file, i read it was suppose to produce an error, but on my project i can launch or publish the app without problem.
I have no direction on how i can debug this,
I put the same message on the github of the .net sdk because i think its a bug, but still no response https://github.com/dotnet/sdk/issues/19035
thanks for your help !
Julien
Upvotes: 1
Views: 4221
Reputation: 188
I finally find the solution with the link provide by @PMF. the key is to put the runtime in the csproj. and now it work (it run in 5.0.6 but its published in 5.0.0)
<PropertyGroup>
<RuntimeFrameworkVersion>5.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
Upvotes: 2
Reputation: 17298
The global.json setting "sdk" selects the SDK, not the target platform. That means it chooses (basically) the compiler to use, not the runtime. The SDK can be anything larger or equal to the target runtime. To select the target runtime, other settings are required.
This page has a good overview over what you can do to select a particular runtime using a runtimeconfig.json
file.
Upvotes: 3