首页 > 解决方案 > Build server of an old ASP.NET 4 application fails building new C# 7, but it works in development

问题描述

I recently start to work on a legacy ASP.NET codebase based on .NET framework 4.0. We managed to pass everything from Visual Studio 2012 to VS 2017, updated the build server with a new version of Jenkins and installing .NET framework 4.7.x.

Locally we can write C# code of the newest version (7.3) and the build works (VS doesn't use MSBuild if I remember right), but when we deploy on the build server the build fails because there MSBuild cannot recognize constructs newer than C# 4.0. To avoid mistakes I fixed the lang version to 4.0 (advanced build properties on projects), so if I write too new C# VS blocks me in dev, but we would like to start using new C#.

We also tried to fix C# 7.3 directly in the project (<LangVersion>7.3</LangVersion> in PropertyGroup inside csproj) and the but ToolsVersion property of Project element (csproj) to 14.0, but then building we MSBuild fails with the error:

CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Here it's explained that what I want to do it is possible: https://www.dotnetcurry.com/dotnet/1427/build-apps-different-dotnet-framework-versions

No matter which .NET framework version we target in the project, the C# language version in use will not change. That’s fine because the vast majority of language features that were introduced in later versions of the language don’t depend on the CLR or specific APIs. They are only syntactic sugar and the bytecode generated by the compiler will still work in .NET framework 2.0.

Anyone have an idea of what mistake are we doing?

标签: c#asp.netmsbuild

解决方案


The problem was that on the build server MSBuild wasn't properly installed and build scripts got an old one. Installing Visual Studio 2017 Build tools and fixing the path on the script we solved.

After we had the problem "The “GetReferenceNearestTargetFrameworkTask” task was not found" we solved like explained here: The "GetReferenceNearestTargetFrameworkTask" task was not found (the right answer depends on what strategy have you used to install VS Buld tools).


推荐阅读