question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core can't build AnyCPU exes

See original GitHub issue

(I may be misunderstanding how things are supposed to work here; apologies if this is more of a question than a bug.)

Consider the following project file:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net47</TargetFramework>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <RuntimeIdentifier>win</RuntimeIdentifier>
  </PropertyGroup>

</Project>

This project builds/runs correctly and generates an AnyCPU exe. Now change the target framework to .NET Core:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <PlatformTarget>AnyCPU</PlatformTarget>
    <RuntimeIdentifier>win</RuntimeIdentifier>
  </PropertyGroup>

</Project>

This project generates a build error: Project is targeting runtime ‘win’ but did not resolve any runtime-specific packages for the ‘Microsoft.NETCore.App’ package. This runtime may not be supported by .NET Core.

If RuntimeIdentifier is win-x86 or win-x64, it builds, but at publish time I suspect (though couldn’t confirm) that the assemblies it generates are not AnyCPU, even though the Platform in the project file was explicitly AnyCPU.

I believe .NET Core still supports AnyCPU for DLLs. But does it really support AnyCPU for EXEs? It looks like today there isn’t a clear answer - you can say you’re building an AnyCPU exe, but you don’t actually get an exe unless you do publish on a Self-Contained Deployment by using a RuntimeIdentifier, and no AnyCPU RuntimeIdentifier (aka just “win”?) is currently supported.

How should this work? Should .NET Core allow creating AnyCPU EXEs? If not, should the build generate an error when OutputType=Exe and Platform=AnyCPU?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
davidmatsoncommented, Jan 29, 2018

FWIW, I think the separation between build & deployment is one of the bigger disconnects between .NET Core and it’s use of MSBuild - things like PlatformTarget were largely the equivalent ways to set things in the past during build time that .NET Core now wants to handle at deployment time. The fact that .NET Core MSBuild projects keep most/all the same build-time mechanisms and then add (potentially duplicate or conflicting) deployment-time mechanisms leads to some surprising/inconsistent behavior. I think this overall design issue is largely capture by #1553, and this is one of many manifestations, but let me know if there’s a better way to provide input on the broader difficulties here.

0reactions
davidmatsoncommented, Jan 29, 2018

Understood. However, is there a need for PlatformTarget to control that knob? If we only had RuntimeIdentifier(s), would that achieve the same result? (Perhaps that’s equivalent to saying AnyCPU is the only PlatformTarget, but you can have architecture-specific RuntimeIdentifiers.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to compile a .NET Core project to "Any CPU ...
As far as I know, the concept of AnyCPU isn't supported in .NET Core (even if you see it available as a setting...
Read more >
Are you using AnyCPU or do you build for fixed targets?
AnyCPU is a concept that doesn't exist anymore in C#/.NET and it is not possible to make .NET applications that targets AnyCPU (since...
Read more >
dotnet build command - .NET CLI
The dotnet build command builds a project and all of its dependencies.
Read more >
dotnet publish command - .NET CLI
The dotnet publish command publishes a .NET project or solution to a directory.
Read more >
C# Target Platforms | x64 vs x86 vs AnyCPU
We have seen that a platform independent .NET assembly can be compiled as AnyCPU, x86 or x64. So what does this mean for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found