Issues switching from .NET SDK 6.0.x to 7.0.100
See original GitHub issueAs a first step in migrating a .NET desktop (WPF,WinForms) application from .NET 6.0 to .NET 7.0 we have been simply switching to the new .NET SDK 7.0.100 by e.g. defining:
{
"sdk": {
"version": "7.0.100",
"rollForward": "latestFeature",
"allowPrerelease": false
}
}
where version
before was say 6.0.403
. No other changes were made. However, this caused two sets of issues and we are wondering if these were expected, why and how to handle them properly. The two issues are:
- Change in behavior when defining
<PublishSingleFile>true</PublishSingleFile>
incsproj
- Change in code analysis rules causing errors
PublishSingleFile
This was a head scratcher. The solution in question will build an AnyCPU
exe that works and runs on both x86 and x64. However, when switching to .NET SDK 7.0.100 this would not work. Either tests would simply not run with issues around bad format for the exe
assembly or similar. Or if trying to run the exe
project e.g. using F5 in visual studio this would simply crash upon start before anything with something like The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core."... code 2147516546 (0x80008082)
. As far as I can tell it turns out behavior has changed (silently) for PublishSingleFile
so this now forces a RuntimeIdentifier
(RID) to be set without any warning or similar. This causes the “format” of the output assembly to become platform specific e.g. win-x64
and hence trying to run x86 tests based on it will fail. Changing this definition to:
<PublishSingleFile Condition="'$(RuntimeIdentifier)' != ''">true</PublishSingleFile>
resolved the issue. Guessing you should simply not define these options in csproj in the future if you have project that you want to build as Any CPU but instead do that only on command line when actually doing publish. Which means these often become redundantly defined.
Code Analysis Changes
This we don’t understand. We have the following defined in Directory.Build.props
with an accompanying .editorconfig
next to sln
at root of git repo.
<AnalysisLevel>latest</AnalysisLevel>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
This compiled fine with zero errors using .NET 6.0 SDK. Switching to .NET SDK 7.0.100 and we had to define the following NoWarn
to the solution building without errors. Note that the set of CAxxxx errors reported in VS and on command line are different this is the union of both to get both building.
<NoWarn>
$(NoWarn);
CA1000;CA1001;CA1002;CA1003;CA1005;CA1008;CA1010;CA1012;CA1017;
CA1021;CA1024;CA1028;CA1030;CA1031;CA1032;CA1036;
CA1040;CA1043;CA1044;CA1045;CA1051;CA1052;CA1060;CA1062;CA1063;CA1065;CA1067;
CA1304;CA1305;CA1307;CA1309;CA1310;CA1311;
CA1401;CA1501;CA1506;CA1508;
CA1707;CA1710;CA1711;CA1716;CA1720;CA1721;CA1724;CA1725;
CA1802;CA1805;CA1810;CA1813;CA1814;CA1815;CA1816;CA1819;
CA1820;CA1823;CA1825;CA1826;CA1829;CA1838;CA1850;CA1851;CA1852;
CA2000;CA2007;CA2008;CA2101;CA2201;CA2208;CA2213;CA2214;CA2217;CA2225;CA2227;
CA5392;CA5394
</NoWarn>
that’s a lot of new code analysis rules suddenly causing errors and this seems off, is this expected?
We would also the have expected to be able to set AnalysisLevel
to 6.0
and get the 6.0 SDK behavior but this had no effect at all. Was this not the intended function of this property?
<AnalysisLevel>6.0</AnalysisLevel>
Further technical details
- Include the output of
dotnet --info
dotnet --info
.NET SDK:
Version: 7.0.100
Commit: e12b7af219
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19044
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.100\
Host:
Version: 7.0.0
Architecture: x64
Commit: d099f075e4
.NET SDKs installed:
3.1.425 [C:\Program Files\dotnet\sdk]
5.0.100 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
5.0.413 [C:\Program Files\dotnet\sdk]
6.0.100-rc.2.21505.57 [C:\Program Files\dotnet\sdk]
6.0.111 [C:\Program Files\dotnet\sdk]
6.0.203 [C:\Program Files\dotnet\sdk]
6.0.306 [C:\Program Files\dotnet\sdk]
6.0.400 [C:\Program Files\dotnet\sdk]
6.0.403 [C:\Program Files\dotnet\sdk]
7.0.100-rc.1.22431.12 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0-rc.2.21480.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0-rc.2.21480.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0-rc.2.21501.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0-rc.1.22427.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
arm64 [C:\Program Files\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version
Visual Studio 17.5.0 Preview 1.0
Issue Analytics
- State:
- Created 10 months ago
- Reactions:3
- Comments:19 (12 by maintainers)
Top GitHub Comments
@martincostello This is fixed in https://github.com/dotnet/roslyn-analyzers/pull/6278
A little side note also discovered a rule
CA1852
that is “undocumented” below link will fail can can’t google it:https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/quality-rules/ca1852
and I hit the top-level statement issue here too:
https://github.com/dotnet/runtime/issues/78270 “Type ‘Program’ can be sealed because it has no subtypes in its containing assembly and is not externally visible”