使用C#7.1构建.NET Core 2.0 EXE文件 [英] Build .NET Core 2.0 EXE file with C# 7.1

查看:71
本文介绍了使用C#7.1构建.NET Core 2.0 EXE文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个项目.它使用的是C#7.1功能,我可以通过Visual Studio运行它,但是当我尝试发布以获取.exe文件时,出现错误:

I have a project I'm trying to build. It's using C# 7.1 features, and I can run it via Visual Studio, but when I try to publish to get an .exe file I get the error:

Agent.cs(8,30): error CS8107: Feature 'async main' is not available in C# 7.
Please use language version 7.1 or greater. [C:\Users\stuarts\Documents\Visual
Studio 2017\Projects\Agent\Agent\Agent.csproj]
CSC : error CS5001: Program does not contain a static 'Main' method suitable
for an entry point [C:\Users\stuarts\Documents\Visual Studio
2017\Projects\Agent\Agent\Agent.csproj]

.csproj(项目)文件:

The .csproj (project) file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <IsPackable>false</IsPackable>
    <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
    <RuntimeFrameworkVersion>2.0.0-*</RuntimeFrameworkVersion>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
    <ApplicationIcon />
    <StartupObject />
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <LangVersion>7.1</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RabbitMQ.Client" Version="5.0.1" />
  </ItemGroup>

</Project>

我要与之建立联系

dotnet publish -c Release -r win10-x64 Agent.csproj

同样,当在Visual Studio中调试时,所有这些都可以正常工作.为什么从控制台应用程序项目模板中获取一个简单的.exe文件太尴尬了!

Again, this all works when debugging in Visual Studio. Why is getting a simple .exe file out of a console application project template so awkward!

推荐答案

您的问题是该部分...

Your problem is that in the section...

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <LangVersion>7.1</LangVersion>
</PropertyGroup>

...您指定在Debug配置中使用C#7.1.

...you specify to use C# 7.1 in the Debug configuration.

但是,有了...

dotnet publish -c Release -r win10-x64 Agent.csproj

...您在Release配置中进行编译.

...you compile in the Release configuration.

您还需要在Release中设置C#7.1.您也可以完全删除条件,从而为任何配置设置语言版本.

You need to set up C# 7.1 in Release, too. You could also remove the condition entirely, which sets up the language version for any configuration.

这篇关于使用C#7.1构建.NET Core 2.0 EXE文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆