Sdk: Poor error with dotnet run and multi-frameworks

Created on 20 Mar 2017  路  5Comments  路  Source: dotnet/sdk

Steps to reproduce

Create exe targeting multiple frameworks e.g.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp1.1;net451</TargetFrameworks>
  </PropertyGroup>

then use dotnet run to run it

Expected behavior

Error message along lines of

You are trying to run an executable project that targets multiple frameworks. Please select a single framework to run with the -f flag.

Actual behavior

Poor error message

Unable to run your project
Please ensure you have a runnable project type and ensure 'dotnet run' supports this project.
The current OutputType is 'Exe'

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.0-preview1-005418)

Product Information:
Version: 2.0.0-preview1-005418
Commit SHA-1 hash: 82c928e1ec

Runtime Environment:
OS Name: Windows
OS Version: 10.0.15061
OS Platform: Windows
RID: win10-x64
Base Path: C:UsersthundAppDataLocalMicrosoftdotnetsdk2.0.0-preview1-005418

Most helpful comment

@InsidiousForce - your issue is separate. Your TargetFramework is netstandard1.6.1, which is not a runnable framework. netstandard is for building libraries that can run on any of the .NET platforms: .NET Framework on Windows, Mono, .NET Core, UWP, Xamarin, etc.

If you want to run your project on .NET Core, please change your TargetFramework to netcoreapp1.1. After doing so, you can remove the PackageReferences to Microsoft.NETCore.Runtime.CoreCLR and Microsoft.NETCore.DotNetHostPolicy, since those will implicitly come through by targeting netcoreapp1.1.

All 5 comments

We had this error message when the command was dotnet run3. However, when we merged the xxx3 verbs to be just xxx, looks like that change was lost.

See https://github.com/dotnet/cli/pull/4403

Looks like we need that change ported again.

dotnet run for me throws that same error, and the debugger in Visual Studio also fails to start with the error

unable to run your project. The "RunCommand" property is not defined.

dotnet publish -c release -r win10-x64 -o build

and

dotnet publish -c release -r ubuntu.16.04-x64 -o build

both work and build functional executables on their target machines.

Before I migrated to csproj with the dotnet migrate tool, I could build on either platform, use dotnet run, and the visual studio debugger worked. My csproj is:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.6.1</TargetFramework>
    <DebugType>portable</DebugType>
    <AssemblyName>OmegaApiUsageGatherer</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>OmegaApiUsageGatherer</PackageId>
    <RuntimeIdentifiers>win10-x64;osx.10.10-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
    <NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="1.1.0" />
    <PackageReference Include="Microsoft.NETCore.DotNetHostPolicy" Version="1.1.0" />
    <PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
    <PackageReference Include="Npgsql" Version="3.2.1" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="AWS.Logger.AspNetCore" Version="1.0.0" />
    <PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.3.0.7" />
    <PackageReference Include="CsvHelper" Version="2.16.3.0" />
    <PackageReference Include="System.Threading.Tasks.Parallel" Version="4.0.1" />
  </ItemGroup>
</Project>

Is this related to the same bug outlined above?

I have visual studio 2017 installed (I removed 2015 first) and this is my dotnet --info:

.NET Command Line Tools (1.0.0)

Product Information:
 Version:            1.0.0
 Commit SHA-1 hash:  e53429feb4

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.0

@InsidiousForce - your issue is separate. Your TargetFramework is netstandard1.6.1, which is not a runnable framework. netstandard is for building libraries that can run on any of the .NET platforms: .NET Framework on Windows, Mono, .NET Core, UWP, Xamarin, etc.

If you want to run your project on .NET Core, please change your TargetFramework to netcoreapp1.1. After doing so, you can remove the PackageReferences to Microsoft.NETCore.Runtime.CoreCLR and Microsoft.NETCore.DotNetHostPolicy, since those will implicitly come through by targeting netcoreapp1.1.

@eerhardt thanks for the clairfication, your changes put me back in working order, and I appreciate it. I got this info for project.json ages ago (during the dark toolchain transition times) when trying to figure out how to build a standalone.

((This probably doesn't belong here (I should go read the defacto source of what all these names are and how they're evolving, if there is one) but I read something on another issue about netcoreapp not being a thing and it will go away in favor of something else. Of course now I can't find it. Do you know how long this will be good for or what the string token is that will replace netcoreapp and is that available now?))

Edit: Or maybe I have it backward and what were previously called .NET Standard Applications are now .NET Core Applications?

Edit edit: Ahh yes, my bad. Thank you again. https://github.com/NuGet/Home/issues/2524

@InsidiousForce - See https://github.com/dotnet/standard/blob/master/docs/faq.md, which is the de facto source in my opinion.

netcoreapp is not going away anytime soon, as far as I know. It is the target framework for .NET Core applications. We are currently working on netcoreapp2.0, the next version after 1.1.

Was this page helpful?
0 / 5 - 0 ratings