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

Raf*_*nho 12 c# publish console-application visual-studio-2017 .net-core-2.0

我一直在尝试使用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>
Run Code Online (Sandbox Code Playgroud)

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

发布个人资料

点击发布后,此错误窗口会显示给我.

发布失败窗口

以下是由它生成的令人敬畏且非常有用的"诊断日志".

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.<---

===================
Run Code Online (Sandbox Code Playgroud)

这些是我已经尝试过但没有用的东西.

  • 清理并重建项目.
  • 删除VS2017缓存和临时文件.
  • 更改发布的目标位置.
  • 将VS2017更新到最新版本并重新启动.

有人可以帮我这个吗?


[更新](解决方案):

我使用dotnet CLI完成了发布工作.在项目根路径上打开cmd(windows power shell也可以)并运行以下命令:

dotnet publish -c Release -r win10-x64
Run Code Online (Sandbox Code Playgroud)

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

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

Kja*_*tan 3

根据此页面,对于 OSX(现在的 MacOS),

.NET Core 2.0 或更高版本,最低版本为osx.10.12-x64

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

<RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
Run Code Online (Sandbox Code Playgroud)

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

但我不明白的是,为什么它会在(a)从命令行运行时以及(b)在较新/其他版本的 Visual Studio 中运行。