I have a .net 4.0 asp.net website (the old ones, with no .csproj). This references a .net framework 4.0 class library (Shared Library A).
I have added a new .net core API project to the solution. This project also needs to talk to Shared Library A.
The solution (I thought) was to move the class library to .net standard 2.0 and then move the website to 4.7.2 which would allow it to reference the .net standard 2.0 project.
To do this I changed the web config for the website so that:
<compilation debug="true" targetFramework="4.7.2">
<httpRuntime maxRequestLength="10000" executionTimeout="1000" requestValidationMode="2.0" targetFramework="4.7.2"/>
This all works in Visual Studio. The solution builds, the website runs & the code in the .netstandard2.0 library functions as expected and is debuggable. I know Visual Studio does some things differently to MSBuild.exe.
The problem is that our CI server cannot build the solution, and neither can "MSBuild.exe" locally.
The command I am running is:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" "[Path to Solution]\AT3.sln"
I then get the error:
warning MSB3268: The primary reference "C:\Work\AT3\at3\wrld\AT3.Common.Utilit ies\bin\Debug\netstandard2.0\AT3.Application.Utilities.dll" could not be resolved because it has an indirect depende ncy on the framework assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.7.2". To resolve this problem, either remove the reference "C:\Work\AT3\at3\wrld\AT3.Common.Utilities\bin\Debug\netstandard2.0\AT3.Application.Uti lities.dll" or retarget your application to a framework version which contains "netstandard, Version=2.0.0.0, Cultur e=neutral, PublicKeyToken=cc7b13ffcd2ddd51"
To try and solve this I added the following line to the section of my web.config:
<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/>
My question is: How can I get this .netstandard2.0 project to resolve using MSBuild.exe? Can a website actually be "4.7.2" and succesfully reference .net standard, or is visual studio lying to me by saying it can?
Notes: I know we need to move the website to a web project. I'm just hoping that this isn't the only solution to this issue as it is a bit of a monolithic website. Our plan is to start slowly migrating code out of App_Code into the .netstandard2.0 libraries.
Thankyou in advance.
To set target . NET runtime version to 6.0, enter <TargetFramework>net6. 0</TargetFramework> version in project's . csproj file directly.
NET standard 2.0 types and members are all packet in a single assemblies netstandard. dll v2. 0 that can be found under C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.
Target framework and profile. A target framework is the particular version of the . NET Framework that your project is built to run on. Specification of a target framework is required because it enables compiler features and assembly references that are exclusive to that version of the framework.
I just learned from my colleague.
You can try add reference in the .Net Standard library's csproj file as below. This works for me.
<Reference Include="netstandard">
<Private>True</Private>
</Reference>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With