Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2017 .Net Core 2.0 Console Application Publish Fail

I've been trying to publish a .Net Core 2.0 Console Application using Visual Studio 2017 Community Edition but it always fails (it runs perfectly inside VS2017).

This is my 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>

Those are the properties of the publish profile that I created.

Publish profile

After click on publish this error window is shown to me.

Publish Fail Window

And below is the awesome and really helpful "diagnostic log" generated by it.

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

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

Those are the things that I have already tried and didn't work.

  • Clean and rebuild project.
  • Delete VS2017 cache and temp files.
  • Change the target location of the publish.
  • Update VS2017 to the latest version and reboot.

Can someone please help me with this?


[UPDATE] (Workaround solution):

I've made the publish work using the dotnet CLI. Open the cmd (windows power shell also work) on the project root path and run the following command:

dotnet publish -c Release -r win10-x64

This will create a publish folder inside the following path bin\Release\netcoreapp2.0\win10-x64\publish, there you will find your .exe file.

But I still get errors when publishing through Visual Studio 2017, it would be better to do it using VS since I wouldn't lose time making it via command line.

like image 841
Rafael Adnet Pinho Avatar asked Dec 26 '17 18:12

Rafael Adnet Pinho


1 Answers

According to this page, for OSX (now MacOS),

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

I suspect that the following in your project file might have been causing some mischief:

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

From what I understand, that OSX-version should be too old to support ( /be supported by?) .NET Core 2.0.

What I don't understand though, is why it would work (a) when run from a command line, and (b) in newer / other versions of Visual Studio.

like image 142
Kjartan Avatar answered Oct 21 '22 03:10

Kjartan