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.

"A self-contained executable cannot be referenced by a non self-contained executable" error on unit tests

See original GitHub issue

I’m getting the error:

The referenced project ‘{project}’ is a self-contained executable. A self-contained executable cannot be referenced by a non self-contained executable.

In my scenario, there’s a project which is indeed self-contained, and a unit test project which depends on that project and tests it.

This error seems to imply that self-contained projects should not have unit tests, which can’t be the case.

An easy workaround is to set <ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>, but it seems like the validation is incorrect in this scenario.

For reference, the self-contained project looks something like:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <DeployOnBuild>true</DeployOnBuild>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
</Project>

and the unit test project:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\TheSelfContainedProject\TheSelfContainedProject.csproj" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
  </ItemGroup>
</Project>

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
dsplaistedcommented, May 13, 2021

This should be fixed with #17594, but until then you can work around it by setting ValidateExecutableReferencesMatchSelfContained to false in your unit test projects.

1reaction
jamers99commented, Jul 28, 2021

@dsplaisted after putting in the recommended workaround we get this error:

C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(4969,5): error MSB3030: Could not copy the file "C:\Repos\eagle\Features\ModelDesigner\ModelDesignerGenerator\obj\Debug\apphost.exe" because it was not found. [C:\Repos\eagle\Features\ModelDesigner\ModelDesignerGenerator\ModelDesignerGenerator.csproj]

Full output logs

PS C:\Repos\eagle> dotnet publish ".\Features\Sample\Sample.Server\Sample.Server.csproj" -r win-x86 -bl
Microsoft (R) Build Engine version 17.0.0-preview-21329-01+1b7661f36 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\MSBuild.dll -bl -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\dotnet.dll -maxcpucount -property:RuntimeIdentifier=win-x86 -restore -target:Publish -verbosity:m .\Features\Sample\Sample.Server\Sample.Server.csproj
  Determining projects to restore...
  All projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
  Eagle.Core -> C:\Repos\eagle\Core\Eagle.Core\bin\Debug\Eagle.Core.dll
  Eagle.Framework.Server.DataUpgrade -> C:\Repos\eagle\Framework\Server\Persistence\DatabaseUpgrade\Eagle.Framework.Server.DataUpgrade\bin\Debug\Eagle.Framework.Server.DataUpgrade.dll
  Eagle.Framework.Server.DataCleanup -> C:\Repos\eagle\Framework\Server\Persistence\DatabaseUpgrade\Eagle.Framework.Server.DataCleanup\bin\Debug\Eagle.Framework.Server.DataCleanup.dll
  Eagle.Framework.Common -> C:\Repos\eagle\Framework\Common\Eagle.Framework.Common\bin\Debug\Eagle.Framework.Common.dll
  TEST.FlaggedFeature -> C:\Repos\eagle\Output\Debug\Sample\Sample\TEST.FlaggedFeature.dll
  Eagle.Framework.Common.Diagnostics -> C:\Repos\eagle\Framework\Common\Eagle.Framework.Common.Diagnostics\bin\Debug\Eagle.Framework.Common.Diagnostics.dll
  EagleServer.Common -> C:\Repos\eagle\Framework\Server\EagleServer.Common\bin\Debug\EagleServer.Common.dll
  Eagle.Framework.Server.Core -> C:\Repos\eagle\Framework\Server\Eagle.Framework.Server.Common\bin\Debug\Eagle.Framework.Server.Core.dll
  ModelDesignerDataExchanger -> C:\Repos\eagle\Features\ModelDesigner\ModelDesignerDataExchanger\bin\Debug\ModelDesignerDataExchanger.dll
  Eagle.Framework.Server.ConflictResolver -> C:\Repos\eagle\Framework\Server\Eagle.Framework.Server.ConflictResolver\bin\Debug\net5\Eagle.Framework.Server.ConflictResolver.dll
  PropertyMetaDataCache -> C:\Repos\eagle\Framework\Server\Persistence\PropertyMetaDataCache\bin\Debug\net5.0\PropertyMetaDataCache.dll
  Eagle.Framework.Server.SelfUpdate -> C:\Repos\eagle\Framework\Server\Eagle.Framework.Server.SelfUpdate\bin\Debug\Eagle.Framework.Server.SelfUpdate.dll
  ModelDesignerHelper -> C:\Repos\eagle\Features\ModelDesigner\ModelDesignerHelper\bin\Debug\ModelDesignerHelper.dll
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Microsoft.Common.CurrentVersion.targets(4969,5): error MSB3030: Could not copy the file "C:\Repos\eagle\Features\ModelDesigner\ModelDesignerGenerator\obj\Debug\apphost.exe" because it was not found. [C:\Repos\eagle\Features\ModelDesigner\ModelDesignerGenerator\ModelDesignerGenerator.csproj]
PS C:\Repos\eagle>

Binlog: binlog.zip

Note that ModelDesignerGenerator is a exe type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The referenced project is a non self-contained executable. ...
The referenced project is a non self-contained executable. A non self-contained executable cannot be referenced by a self-contained executable.
Read more >
Error generated when executable project references ...
NET 5 where compile-time errors are generated when an executable references an executable whose SelfContained value is different.
Read more >
dotnet build error NETSDK1150 | OutputType exe #18116
It seems like a weird error "A non self-contained executable cannot be referenced by a self-contained executable." (NETSDK1150) when building ...
Read more >
The referenced project is a non self-contained executable. A ...
[Solved]-The referenced project is a non self-contained executable. A non self-contained executable cannot be referenced by a self-contained executable-.net- ...
Read more >
Spring Boot Reference Documentation
Executable jars (sometimes called “fat jars”) are archives containing your compiled classes along with all of the jar dependencies that your code needs...
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