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

问题描述 投票:11回答:1

我一直在尝试使用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>

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

Publish profile

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

Publish Fail Window

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

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

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

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

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

有人可以帮我这个吗?


[更新](解决方案):

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

dotnet publish -c Release -r win10-x64

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

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

c# visual-studio-2017 console-application publish .net-core-2.0
1个回答
2
投票

根据this page的说法,对于OSX(现在的MacOS),

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

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

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

根据我的理解,OSX版本应该太旧而不能支持(/得到?).NET Core 2.0。

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

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.