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.

`dotnet build` error NETSDK1150 | OutputType exe

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
fr4glescommented, 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>
2reactions
dsplaistedcommented, Jul 29, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

The referenced project is a non self-contained executable. ...
NET SDK 5, an error is generated if an executable project references another executable project and the SelfContained values don't match. Now, ...
Read more >
Error generated when executable project references ...
NET SDK 5+ produces compile-time errors NETSDK1150 and NETSDK1151 when it detects mismatched executable references.
Read more >
NETSDK1100: Set the `EnableWindowsTargeting` property ...
Learn about the .NET SDK error message that instructs you to set the EnableWindowsTargeting property to true.
Read more >
MSBuild reference for .NET SDK projects
The UseAppHost property controls whether or not a native executable is created for a deployment. A native executable is required for self- ...
Read more >
dotnet build command - .NET CLI
Executable or library output. Whether the project is executable or not is determined by the <OutputType> property in the project file. The ...
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