Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the C# version in Visual Studio 2019

I'm using visual studio 2019 and I'm trying to change my C# version. The reason I am doing this is that the build servers I use use an older version of VS / MSBuild to build and deploy code (this is outside my control). Therefore I need to use C# 5.

On previous versions of visual studio, you could do this from the menu in [Project] -> Properties -> Build -> Advanced. For VS2019 Microsoft, in their infinite wisdom, has decided to make this harder. Apparently you need to edit the project file manually and add:

<PropertyGroup>
   <LangVersion>[some version here]</LangVersion>
</PropertyGroup>

To your project file manually. That's all well and good, but I can't seem to get that working. It just ignores it, even after I unload and reload it. Here is a snapshot of my project file:

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   <LangVersion>5</LangVersion>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{58FE5465-851B-471F-B6A9-9C861FA5C022}</ProjectGuid>
    <OutputType>Library</OutputType>
...

Any idea how I can make this work? It's probably something really silly I'm missing. Note: I did see this previous question but it was lacking detail.

like image 220
Armand Bernard Avatar asked Feb 16 '20 09:02

Armand Bernard


People also ask

What is change function C?

In the function 'change' the pointer is copied (passed by value) and it is used in the function as it would have in main. No need for malloc.

Can you change define in C?

Description. In the C Programming Language, the #define directive allows the definition of macros within your source code. These macro definitions allow constant values to be declared for use throughout your code. Macro definitions are not variables and cannot be changed by your program code like variables.

What is called function in C?

A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a function. Functions are used to perform certain actions, and they are important for reusing code: Define the code once, and use it many times.

What is function declaration in C?

A function consist of two parts: Declaration: the function's name, return type, and parameters (if any) Definition: the body of the function (code to be executed)

How to change the text color in C++ language?

If You want to change the Text color in C++ language There are many ways. In the console, you can change the properties of output. click this icon of the console and go to properties and change color. The second way is calling the system colors. Highly active question.

Is it possible to modify a string in C?

No, you cannot modify it, as the string can be stored in read-only memory. If you want to modify it, you can use an array instead e.g. Or alternately, you could allocate memory using malloc e.g. Show activity on this post. A lot of folks get confused about the difference between char* and char [] in conjunction with string literals in C.

Why do we need to replace the C drive?

It is also used to store applications and their related files. You see the importance of C drive and you may need to replace C drive in following situations: Your current drive has experienced a hardware failure and you can’t fix it.

How to change C drive with SSD?

For more and more people choose SSDs as their main hard drives, I’ll show you how to change C drive with SSD using AOMEI Backupper in the coming part. ● Connect the target SSD to your computer and make sure it is detected. It is recommended to connect the SSD internally if there is an extra SSD slot inside your computer.


1 Answers

The simplest way to change C# language version in Visual Studio 2019 is to:

  1. Right-click on a project in Solution Explorer (files tree) in Visual Studio;
  2. Then from the popup menu select "edit project item properties" -> "c# language level";
  3. On the list you will see all possible c# versions.

That's it! It works like a charm. Please note, that you should not do any other changes to the project files - so if you did any, please revert them to the original state. Also you don't need any <LangVersion> tags.

like image 166
Marcin Avatar answered Oct 18 '22 14:10

Marcin