VS 2017 .Net Core 2.0 控制台应用程序发布失败

VS 2017 .Net Core 2.0 Console Application Publish Fail

我一直在尝试使用 Visual Studio 2017 社区版发布 .Net Core 2.0 控制台应用程序,但它总是失败(它 运行 完全在 VS2017 中)。

这是我的 CSPROJ:

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

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  <TargetFramework>netcoreapp2.0</TargetFramework>
  <ApplicationIcon />
  <StartupObject />
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
</ItemGroup>

<ItemGroup>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
</ItemGroup>

<ItemGroup>
  <Folder Include="Properties\PublishProfiles\" />
</ItemGroup>

<ItemGroup>
  <ProjectReference Include="..\SharedLib\SharedLib.csproj" />
</ItemGroup>

<ProjectExtensions>
  <VisualStudio>
    <UserProperties appsettings_1json__JSONSchema="http://json.schemastore.org/compilerconfig" />
  </VisualStudio>
</ProjectExtensions>

</Project>

这些是我创建的发布配置文件的属性。

点击发布后,我看到了这个错误 window。

下面是它生成的很棒且非常有用的 "diagnostic log"。

System.AggregateException: One or more errors occurred. ---> System.Exception: Publishing failed.
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.Model.DefaultPublishSteps.<>c__DisplayClass22_0.<IsBuildCompletedSuccessfully>b__1()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.Model.DefaultPublishSteps.<DefaultCorePublishStep>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ApplicationCapabilities.Publish.ViewModel.ProfileSelectorViewModel.<RunPublishTaskAsync>d__108.MoveNext()
---> (Inner Exception #0) System.Exception: Publishing failed.<---

===================

这些是我已经尝试过但没有奏效的方法。

有人可以帮我解决这个问题吗?


[更新](解决方案):

我使用 dotnet CLI 完成了发布工作。 在项目根路径和运行下打开cmd(windowspowershell也可以)以下命令:

dotnet publish -c Release -r win10-x64

这将在以下路径 bin\Release\netcoreapp2.0\win10-x64\publish 中创建一个发布文件夹,您将在其中找到您的 .exe 文件。

但是我在 Visual Studio 2017 发布时仍然出现错误,最好使用 VS 来完成,因为我不会浪费时间通过命令行来完成。

根据 this page,对于 OSX(现在是 MacOS),

the .NET Core 2.0 or later versions, minimum version is osx.10.12-x64

我怀疑您的项目文件中的以下内容可能造成了一些恶作剧:

<RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>

据我了解,OSX 版本应该太旧而无法支持(/被支持?).NET Core 2.0。

但我不明白的是,为什么它会工作 (a) 当 运行 来自命令行时,以及 (b) 在 Visual Studio.[= 的较新/其他版本中14=]

我正在使用 Visual Studio 2017,.Net Core 2.2。在项目发布页面上:

  • 单击配置 link
  • 目标运行时便携更改为win-x64

它解决了我的问题。