"A self-contained executable cannot be referenced by a non self-contained executable" error on unit tests
See original GitHub issueI’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:
- Created 2 years ago
- Comments:15 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This should be fixed with #17594, but until then you can work around it by setting
ValidateExecutableReferencesMatchSelfContained
to false in your unit test projects.@dsplaisted after putting in the recommended workaround we get this error:
Full output logs
Binlog: binlog.zip
Note that
ModelDesignerGenerator
is a exe type.