sdk: "A self-contained executable cannot be referenced by a non self-contained executable" error on unit tests
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>
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (5 by maintainers)
Commits related to this issue
- Fix test projects which reference self-contained Exes Fix #17579 — committed to dsplaisted/sdk by dsplaisted 3 years ago
- Fix test projects which reference self-contained Exes Fix #17579 — committed to dsplaisted/sdk by dsplaisted 3 years ago
- fix MNTR local build for .NET 5 some .NET 5 SDKs are affected by https://github.com/dotnet/sdk/issues/17579 Added recommended work-around to ensure production of local NuGet packages still — committed to Aaronontheweb/akka.net by Aaronontheweb 3 years ago
- fix MNTR local build for .NET 5 (#5177) some .NET 5 SDKs are affected by https://github.com/dotnet/sdk/issues/17579 Added recommended work-around to ensure production of local NuGet packages still — committed to akkadotnet/akka.net by Aaronontheweb 3 years ago
This should be fixed with #17594, but until then you can work around it by setting
ValidateExecutableReferencesMatchSelfContainedto 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
ModelDesignerGeneratoris a exe type.@dsplaisted We also have this scenario by design. We have our unit tests alongside the code that they test and the files get excluded from release builds. This means that all of our Projects (in Debug mode anyway) are Test Projects
This is also happening dotnet 6 Preview 6! This is a big stopper for us and we can’t even upgrade to the latest version of dotnet 5 because that also has the problem. @dsplaisted when will this be fixed in dotnet 5 and dotnet 6?
Happening here on SDK 6.0.100-preview.5.21302.13 as well, when is this going to be released?