Build fails targeting 4.5.2 if dotnet core SDK not installed
See original GitHub issueOur builds are failing on build agents without dotnet core SDK installed after upgrading to 4.0.3 from 3.2.5 and targetting .NET 4.5.2.
Steps to reproduce
Upgrade from 3.2.5 to 4.0.3 using NuGet package manager (reproduced both on Visual Studio 2017 latest release and Jetbrains Rider latest release), targeting .NET 4.5.2
The issue
Build will fail if dotnet core is not installed on the building machine.
Error message:
error CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
This is how nuget package manager modifies one of the .csproj files (see the reference to netstandard in HintPath):
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.5.0\lib\netstandard1.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.0\lib\portable-net45+win8+wp8+wpa81\System.Threading.Tasks.Extensions.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
<Private>True</Private>
</Reference>
Further technical details
Npgsql version: 4.0.3 PostgreSQL version: not relevant as it’s not a runtime issue. Operating system: Windows Server 2012 (for build machines). Windows 10 and MacOs for dev machines where code changes are implemented.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Targeting pack for .NET 4.5.2 not installed
How I found that link. First, choose option 1, "Change the target to .NET Framework 4.5". Next, go to the project options of...
Read more >NETSDK1045: The current .NET SDK does not support ...
This error occurs when the build tools can't find the version of the .NET SDK that's needed to build a project. This is...
Read more >Troubleshoot .NET Framework targeting errors
This article provides resolutions for MSBuild errors that might occur because of reference issues.
Read more >Building a project that target .NET Framework 4.5 in Visual ...
So, the fix is simple: just copy the files from that package to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4 ...
Read more >Visual Studio 17.4.5 no older net core targeting
Description. I cannot see older net core sdk in projects template (below .net core 2.1). Configuration .Net core environment path order:.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am having the exact issue here within a F# project (dotnet build):
error FS3033: The type provider 'FSharp.Data.Sql.SqlTypeProvider' reported an error: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
I am in macOS, clean
dotnet
install with version 2.1.403, however, the following two workarounds work for me:I got the idea of downgrading from this post: https://community.powerbi.com/t5/Desktop/a-problem-connecting-wiht-postgresql-database/td-p/431097
@stefanoric, sorry for disappearing for so long, I was very occupied with non-Npgsql things.
I’ve checked, and the references to netstandard assemblies can be considered the expected behavior. The System.ValueTuple package, for example, contains assemblies for
net461
,net47
,portable-net40+sl4+win8+wp8
andnetstandard1.0
(among several others). Now, .NET Framework 4.5 supports .NET Standard 1.0, and it would appear that the nuget resolution rules favor that overportable-net40+sl4+win8+wp8
. This doesn’t really have anything to do with Npgsql - it’s about .NET dependency resolution.Now, you can probably manually change your csproj to depend on the
portable-net40+sl4+win8+wp8
instead. However, at least in theory there shouldn’t be a problem to reference anetstandard10
library from a .NET Framework project - this is supposed to work just fine. But it’s true that .NET Standard 1.0 involves its complications, so this may be a valid workaround at least for now.Note that if I do the same experiment from a .NET Framework 4.6.1 project, I get a reference to the
net461
assembly of System.ValueTuple instead.System.Runtime.CompilerServices.Unsafe
does referencenetstandard20
but that’s supposed to be much less complicated than pre-2.0, so it should not give you any trouble whatsoever.@hnfmr this may or may not also address your comment, there isn’t enough information to know. If you still have an Npgsql-related issue, please open a separate issue with a full code sample.
@dropyghost you’re issue doesn’t seem related at all - I checked and found that a reference toSystem.ValueTuple is indeed missing from the VSIX csproj. I opened #2230 to address that for 4.0.4.