Correct .NET Core SDK to build netstandard20 library - msbuild

I have a few libraries with target framework netstandard20. These libraries are consumed by a few .net framework 4.6.1 libraries.
The IT department uninstalled the .NET Core 2.0 from the build server because of some security vulnerability. All the libraries that use netstandard20 are now failing with the following error:
C:\bamboo6104...>nuget restore
MSBuild auto-detection: using msbuild version '16.11.2.50704' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\bin'.
C:\bamboo6104\xml-data\build-dir\BAM-CUS-JOB1...\netstandard\xxx.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
The Build Server already has Visual Studio 2019. What version of SDK need to be installed for the build to pass? I have the following SDKs on my laptop:
Will installing 2.1.526 version resolve the build issue?
I can't upgrade the libraries to .NET 5 or 6 due to we have numerous libraries with the same problem and upgrade is not a priority.

Related

How to build application targetting .Net 4/4.5 on CentOs

I have a lot of legacy code that builds fine on Windows with .Net 4.5
I am trying to build the same on CentOS with dotnet-sdk for automation and licensing issues.
Following the Microsoft link after installing the required packages, this command fails
$ dotnet msbuild sharpTest.sln
/usr/share/dotnet/sdk/5.0.301/Microsoft.Common.CurrentVersion.targets(1216,5): error MSB3644: The reference
assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install the Developer Pack
(SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework
Developer Packs at https://aka.ms/msbuild/developerpacks
Since I installed dotnet-sdk-5, it seems the solution fails to build. But I could not locate .Net framework 4 for CentOS
How do I resolve this ?
It's referencing .NETFramework. .NETFramework V4.0 is not xplat and therefore not available on anything else than windows. You should try to re-target your solution to net5.0 and make it independent of Windows specific dependencies.
To re-target to net5.0 try the dotnet upgrade-assistant (it's a dotnet tool). Do this on a windows machine first. To address any windows dependencies that won't work outside windows or .NetFramework see the Overview of porting from .NET Framework to .NET

Cannot add .NET 5 source code as a project reference

I've downloaded .NET 5 according to these instructions.
I can build the Antiforgery.slnf in Visual Studio with no errors.
I've added it as a project reference in a different solution with an ASP.NET Core 5 app.
But I'm getting these errors:
'..\..\..\..\..\..\aspnetcore\src\Antiforgery\src\Microsoft.AspNetCore.Antiforgery.csproj' targets 'net6.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v5.0'. AntiForgeryTest C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 1662
NU1201 Project Microsoft.AspNetCore.Antiforgery is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Project Microsoft.AspNetCore.Antiforgery supports: net6.0 (.NETCoreApp,Version=v6.0) AntiForgeryTest C:\Users\Davidk\source\repos\AntiForgeryTest\WebApplication2\AntiforgeryTest.csproj 1
It seems as though the current version of ASP.NET Core source code in Github is version net6.0, and the current version available in Visual Studio when creating a new project is only net5.0.
Do I need to get version net5.0 of the source code? I'd prefer to not have to do that since it's taken me hours just to get the .NET Core source code to build.
Any recommendations would be greatly appreciated.
I'm using Visual Studio Enterprise 2019 version 16.8.2 and here is the list of the installed SDKs:

Cakebuild script uses vs 2017 and build fails

I'm working on a legacy project based on Habitat home. There is a PowerShell script which I'm using since there is no cake extension for vs2019. But I'm getting those errors
Version 2.2.300 of the .NET Core SDK requires at least version 16.0.0
of MSBuild. The current available version of MSBuild is
15.8.169.51996. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently
available.
and
C:\Program Files (x86)\Microsoft Visual
Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(112,5):
error : The current .NET SDK does not support targeting .NET Core
2.2. Either target .NET Core 1.1 or lower, or use a version of the .NET SDK that supports .NET Core 2.2.
I've changed the cake-config.json like this - "BuildToolVersions": "VS2019". But nothing cahnged.
Is there another config/xml or something that has to be changed?

MsBuild failing for .Net Standard project with error "Package System.Security.Cryptography.ProtectedData, version x.x.x was not found"

Project Setup : Mixed framework solution
.Net Framework 4.6.2 projects in solution : 15
.Net Standard 2.0 projects in solution - 1
Development Machine
Visual Studio 2017(15.7.4) : Builds without any errors
Build Server
TeamCity Version 2017.1.3
Build Steps
Nuget Restore(3.4.4)
dotnet Restore
MSBuild( Build Tools 2017), Tools Version 15.0
Build fails with following error in the .net standard 2.0 project : [ResolvePackageAssets] C:\Program Files\dotnet\sdk\2.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): Package System.Security.Cryptography.ProtectedData, version 4.4.0 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.
What's interesting is I can't find reference or use of System.Security.Cryptography.ProtectedData anywhere in the project. Any help is greatly appreciated.
P.S - Can't use dotnet build, as the solution needs building of licenses.licx files, and the component which builds it (Microsoft.Build.Tasks.LC) is not ported to .Net Core. The suggestion from various posts was to use MsBuild.exe

MSBuild error when specifying PublishProfile for ASP.NET.Core project

I have an ASP.NET Core 1.1.2 project targeting .NET Framework 4.6.2. I recently installed the latest version of Visual Studio (15.2 26430.16), and now I can't build the project using MSBuild version 15.1.1012.6693. The error occurs when using a PublishProfile.
The MSBuild command is:
msbuild D:\project\project.csproj /p:DeployOnBuild=true /p:PublishProfile=dist
And the error is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets(54,5):
error MSB4062: The "TransformWebConfig" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\..\..\tools\net46\\Microsoft.NET.Sdk.Publish.Tasks.dll.
Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk.Publish\tools\net46\Microsoft.NET.Sdk.Publish.Tasks.dll' or one of its dependencies.
An attempt was made to load a program with an incorrect format.
Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
[D:\project\project.csproj]
It works when not specifying a publish profile. However when publishing the project from Visual Studio, everything works as expected.
This is known bug of the tooling when building using the 64 bit MSBuild version (build server, command line). See this GitHub issue for details.
Since this issue has been fixed, you need to upgrade to the recently released 15.3.* versions of Visual Studio / MSBuild and probably also 2.0.0 version of the .NET Core SDK.