Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet build error NETSDK1150 | OutputType exe #18116

Open
fr4gles opened this issue Jun 5, 2021 · 10 comments
Open

dotnet build error NETSDK1150 | OutputType exe #18116

fr4gles opened this issue Jun 5, 2021 · 10 comments

Comments

@fr4gles
Copy link

fr4gles commented Jun 5, 2021

Overview

  1. dotnet restore "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --runtime="win-x64" --force
  2. dotnet build "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --configuration="Release" --framework="net5.0" --runtime="win-x64" --no-incremental --no-restore --force (please see environment_1: output_1 & conf_1 and environment_2: output_2 & conf_2)
  3. It works ok on dotnet 5 and msbuild on environment_2 (output_2 & conf_2) but is not working on environment_1 (output_1 & conf_1)

Error on environment_1 (output_1 & conf_1)

C:\Program Files\dotnet\sdk\5.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1076,5): error NETSDK1150: The referenced project '(...)A.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [(...)B.csproj]

Repro solution contains two sample projects

  • A.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>
  • B.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\A\A.csproj" />
  </ItemGroup>
</Project>

environment_1 | conf_1

  • dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.300
 Commit:    2e0c8c940e

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

Host (useful for support):
  Version: 5.0.6
  Commit:  478b2f8c0e

.NET SDKs installed:
  2.2.402 [C:\Program Files\dotnet\sdk]
  3.1.202 [C:\Program Files\dotnet\sdk]
  3.1.302 [C:\Program Files\dotnet\sdk]
  3.1.409 [C:\Program Files\dotnet\sdk]
  5.0.102 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.203 [C:\Program Files\dotnet\sdk]
  5.0.300 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • dotnet msbuild -version
Microsoft (R) Build Engine version 16.10.0+4242f381a for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

16.10.0.26302

environment_2 | conf_2

  • dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.201
 Commit:    a09bd5c86c

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

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  3.1.407 [C:\Program Files\dotnet\sdk]
  5.0.104 [C:\Program Files\dotnet\sdk]
  5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
  • dotnet msbuild -version
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

16.9.0.11203

environment_1 | output_1

PS C:\Source\Solution1> dotnet restore "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --runtime="win-x64" --force
  Determining projects to restore...
  Restored C:\Source\Solution1\A\A.csproj (in 141 ms).
  Restored C:\Source\Solution1\B\B.csproj (in 141 ms).
PS C:\Source\Solution1> dotnet build "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --configuration="Release" --framework="net5.0" --runtime="win-x64" --no-incremental --no-restore --force
Microsoft (R) Build Engine version 16.10.0+4242f381a for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\5.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1076,5): error NETSDK1150: The referenced project '..\A\A.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Source\Solution1\B\B.csproj]
  A -> C:\Source\Solution1\A\bin\Release\net5.0\win-x64\A.dll

Build FAILED.

C:\Program Files\dotnet\sdk\5.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1076,5): error NETSDK1150: The referenced project '..\A\A.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Source\Solution1\B\B.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.26

environment_2 | output_2

PS C:\Source\Solution1> dotnet restore "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --runtime="win-x64" --force
  Determining projects to restore...
  Restored C:\Source\Solution1\B\B.csproj (in 5.48 sec).
  Restored C:\Source\Solution1\A\A.csproj (in 5.48 sec).
PS C:\Source\Solution1> dotnet build "C:\Source\Solution1\Solution1.sln" --verbosity="minimal" --configuration="Release" --framework="net5.0" --runtime="win-x64" --no-incremental --no-restore --force
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  A -> C:\Source\Solution1\A\bin\Release\net5.0\A.dll
  A -> C:\Source\Solution1\A\bin\Release\net5.0\win-x64\A.dll
  B -> C:\Source\Solution1\B\bin\Release\net5.0\win-x64\B.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:05.33
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jun 5, 2021
@fr4gles fr4gles changed the title dotnet build error NETSDK1150 | OutputType exe dotnet build error NETSDK1150 | OutputType exe Jun 5, 2021
@fr4gles
Copy link
Author

fr4gles commented Jun 5, 2021

By the accident I've discovered that it's a Breaking change: Error generated when executable references executable - .NET | Microsoft Docs
and my error looks like intended behavior - breaking change in .NET SDK 5.0.300

I've tested suggested change <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
and it works...

It would be nice to add error messages to documentation pages because that way it would be indexed and more people would find problem easier rather that spending several hours trying to isolate problem.

  • Updated B.csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>

    <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>

  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\A\A.csproj" />
  </ItemGroup>
</Project>

@PathogenDavid
Copy link
Contributor

I second the notion that there should be a link to the documentation in the error message. It's also unclear to me why this is even an error instead of a warning.


Some developers want to reference an executable project from another executable project so that both apps are placed in and are runnable from the same output folder.

This doesn't describe my use of this feature. I somewhat regularly use exe-to-exe references in quick temporary prototypes to use classes out of an executable in another. (Or in today's case, I use it to run unit tests outside the test runner when the test runner is interfering with things.)

@fr4gles
Copy link
Author

fr4gles commented Jun 6, 2021

We are using hangfire for job scheduling.

My use case: we are referencing first project (A.csproj) which is console hangfire worker with defined jobs in second project (B.csproj) that is aspnet with mainly hargfire front.

This breaking change forced us to add ValidateExecutableReferencesMatchSelfContained, if it won't be an option we would have to extract our logic to another library layer.

I also don't see a reason why it's an error.
And you get error just by upgrading existing dotnet 5 from dotnet 5.0.2xx to 5.0.3xx. it works fine since dotnet core 2.0 without any warning.

@programmer694
Copy link

Same issue here when referencing another exe. It seems like a weird error "A non self-contained executable cannot be referenced by a self-contained executable." (NETSDK1150) when building with "dotnet publish projecta -c Release -r win-x64 master/projecta". Projecta references projectb, indeed also outputtype exe, like projecta, but the default when building should be "true" according to the documentation, so the references projectb should also be build self-contained before building projecta. Why then this error? It indeed disappears when removing the outputtype exe, but I need that exe.

So what happens when building self-contained more explicitly? "dotnet publish projecta -c Release -r win-x64 --self-contained true master/projecta". Then I still get a complaint, but this time dotnet continues the build, but the complaint is: "It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false." (NETSDK1031). I did actually specify the runtime identifier...

It seems weird to have to include the flag "ValidateExecutableReferencesMatchSelfContained" in the project, while there is nothing wrong with my project, all references are also build with the same command, so self-contained.

Btw: this all started since the most recent update of dotnet, running sdk 5.0.300.

@marcpopMSFT marcpopMSFT self-assigned this Jun 9, 2021
@jacekard
Copy link

jacekard commented Jun 10, 2021

Hi,
in my case my main project, described as follows:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>

was referencing another project (Web API) that was defined as <Project Sdk="Microsoft.NET.Sdk.Web"> (without defined output type as "exe") which resulted in breaking the build while using sdk 5.0.30x.

My solution was to change Sdk.Web to Sdk in csproj for Web API project, but I confirm that ValidateExecutableReferencesMatchSelfContained set to false fixes this problem as well.

@marcpopMSFT
Copy link
Member

@dsplaisted more feedback on the exe reference error.

@programmer694
Copy link

Same issue here when referencing another exe. It seems like a weird error "A non self-contained executable cannot be referenced by a self-contained executable." (NETSDK1150) when building with "dotnet publish projecta -c Release -r win-x64 master/projecta". Projecta references projectb, indeed also outputtype exe, like projecta, but the default when building should be "true" according to the documentation, so the references projectb should also be build self-contained before building projecta. Why then this error? It indeed disappears when removing the outputtype exe, but I need that exe.

So what happens when building self-contained more explicitly? "dotnet publish projecta -c Release -r win-x64 --self-contained true master/projecta". Then I still get a complaint, but this time dotnet continues the build, but the complaint is: "It is not supported to build or publish a self-contained application without specifying a RuntimeIdentifier. You must either specify a RuntimeIdentifier or set SelfContained to false." (NETSDK1031). I did actually specify the runtime identifier...

It seems weird to have to include the flag "ValidateExecutableReferencesMatchSelfContained" in the project, while there is nothing wrong with my project, all references are also build with the same command, so self-contained.

Btw: this all started since the most recent update of dotnet, running sdk 5.0.300.

I ended up stripping the exe part of the project and putting that in a separate project, next to a reference to the original project. Quite weird that dotnet generates a dll+exe when outputtype is exe, but does not allow you to reference the project with the exe for a self-contained build.

@admalledd
Copy link

I am also having this problem, and where my use case is having a unit test project referencing the exe project.

I feel this error is flawed or too broad, encouraging me to disable across all projects...

@dsplaisted
Copy link
Member

I've sent a PR to add a link to these error messages which should help those who encounter it find out how to turn it off: #19392

@dsplaisted dsplaisted removed their assignment Jul 29, 2021
@dsplaisted dsplaisted removed the untriaged Request triage from a team member label Jul 29, 2021
@dsplaisted dsplaisted added this to the Discussion milestone Jul 29, 2021
v-wuzhai pushed a commit that referenced this issue Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants