Devenv命令行构建不使用c# 7.2语言特性

时间:2021-07-26 00:10:43

After upgrading to c# 7.2, our automated build server kicked a compile error. "Features 'readonly references' is not available in c#7.0. Please use language 7.2 or greater."

在升级到c# 7.2之后,我们的自动构建服务器抛出了一个编译错误。c#7.0中没有“只读引用”的特性。请使用7.2或以上的语言

The project that is failing is set to use "latest minor version", which is 7.2, in the advanced build tab. The project builds and runs fine in visual studio. The command line fails with that error. Setting the build setting explicitly to 7.2 instead of "latest minor version" also fails.

失败的项目将在advanced build选项卡中使用“最新的次要版本”,即7.2。该项目在visual studio中构建并运行良好。该错误导致命令行失败。将构建设置显式设置为7.2而不是“最新的次要版本”也会失败。

Why is the command line failing to load the latest language feature? And it works in the VS ide?

为什么命令行不能加载最新的语言特性?它在VS ide中有效吗?

The command line is "devenv SolutionFile.sln /Build Release"

命令行是“devenv SolutionFile”。sln /构建发布”

The sample application to reproduce/demonstrate this is a WPF app, with a form and a button, and a handler to pass a struct.

复制/演示的示例应用程序是一个WPF应用程序,包含一个表单和一个按钮,以及一个传递结构体的处理程序。

public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private struct Test123
        {
            public string test;
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Test123 test;
            test.test = "foo";
            Test(test);
        }

        private void Test(in Test123 test)
        {
            // do nothing
        }
    }

Devenv命令行构建不使用c# 7.2语言特性

Update: Also, there is a mismatching version in the commandline. The commandline opens and says it is on v15.5.1. However, the devenv exe gives an earlier version. Devenv命令行构建不使用c# 7.2语言特性

更新:命令行中还有一个不匹配的版本。命令行打开并说它在v15.5.1上。然而,devenv exe给出了一个早期版本。

1 个解决方案

#1


0  

I think the best way to verify that C# 7.2 is being enabled is to edit the csproj file directly, and make sure <LangVersion>7.2</LangVersion> is included in all your build configurations.

我认为验证c# 7.2是否启用的最佳方法是直接编辑csproj文件,并确保 7.2 包含在所有构建配置中。

For example, release configuration should look like this:

例如,发布配置应该如下所示:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <PlatformTarget>AnyCPU</PlatformTarget>
  <DebugType>pdbonly</DebugType>
  <Optimize>true</Optimize>
  <OutputPath>bin\Release\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <LangVersion>7.2</LangVersion>
</PropertyGroup>

#1


0  

I think the best way to verify that C# 7.2 is being enabled is to edit the csproj file directly, and make sure <LangVersion>7.2</LangVersion> is included in all your build configurations.

我认为验证c# 7.2是否启用的最佳方法是直接编辑csproj文件,并确保 7.2 包含在所有构建配置中。

For example, release configuration should look like this:

例如,发布配置应该如下所示:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <PlatformTarget>AnyCPU</PlatformTarget>
  <DebugType>pdbonly</DebugType>
  <Optimize>true</Optimize>
  <OutputPath>bin\Release\</OutputPath>
  <DefineConstants>TRACE</DefineConstants>
  <ErrorReport>prompt</ErrorReport>
  <WarningLevel>4</WarningLevel>
  <LangVersion>7.2</LangVersion>
</PropertyGroup>