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

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

Closed
dfederm opened this issue May 12, 2021 · 15 comments
Labels
untriaged Request triage from a team member

Comments

@dfederm
Copy link

dfederm commented May 12, 2021

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>
@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 May 12, 2021
@dfederm
Copy link
Author

dfederm commented May 12, 2021

@dsplaisted Looks like you recently adding this validation. How should this interact with unit tests?

@dsplaisted
Copy link
Member

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

@BobSilent
Copy link

This issue also occurs in .NET 6.0 Preview 5

@jamers99
Copy link

jamers99 commented Jul 9, 2021

Happening here on SDK 6.0.100-preview.5.21302.13 as well, when is this going to be released?

@jamers99
Copy link

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?

@dsplaisted
Copy link
Member

dsplaisted commented Jul 16, 2021

You should be able to set the ValidateExecutableReferencesMatchSelfContained MSBuild property to false suppress this error.

If you can share a binlog of your build where you're getting this error, we should be able to look into why it is still triggering for you.

@jamers99
Copy link

binlog.zip

dotnet.exe publish Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj -o Output\Debug\publish\EagleCompanyManager\EagleCompanyManager -c Debug -p:TreatWarningsAsErrors=true -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:PublishDir=C:\Repos\eagle\Output\Debug\publish\EagleCompanyManager\EagleCompanyManager -property:RuntimeIdentifier=win-x86 -property:Configuration=Debug -p:TreatWarningsAsErrors=true -restore -target:Publish -verbosity:m Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj
  Determining projects to restore...
  Restored C:\Repos\eagle\Core\Eagle.Core\Eagle.Core.csproj (in 225 ms).
  Restored C:\Repos\eagle\Framework\Common\Eagle.Framework.Common\Eagle.Framework.Common.csproj (in 406 ms).
  Restored C:\Repos\eagle\Framework\Common\Eagle.Framework.Common.Diagnostics\Eagle.Framework.Common.Diagnostics.csproj (in 556 ms).
  25 of 28 projects are up-to-date for restore.
  You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\EagleCompanyManager.ModelTests\EagleCompanyManager.ModelTests.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\EagleCompanyManagerBL\EagleCompanyManagerBL.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\EagleCompanyManager.Model\EagleCompanyManager.Model.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\..\..\Framework\Server\Persistence\DatabaseUpgrade\Eagle.Framework.Server.DataUpgrade\Eagle.Framework.Server.DataUpgrade.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\..\ModelDesigner\ModelDesignerGenerator\ModelDesignerGenerator.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.6.21355.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(1045,5): error NETSDK1150: The referenced project '..\..\ModelDesigner\ModelDesignerHelper\ModelDesignerHelper.csproj' is a non self-contained executable.  A non self-contained executable cannot be referenced by a self-contained executable. [C:\Repos\eagle\Features\EagleCompanyManager\EagleCompanyManager.Server\EagleCompanyManager.Server.csproj]

@dsplaisted
Copy link
Member

Thanks for the quick binlog. The errors are happening because the projects being referenced are test projects. We fixed the case where a test project was referencing an Exe, but this is the opposite case where an Exe is referencing a test project.

I think we should also fix this case. I'm curious though why you have test projects referenced by your app project. Is this intentional?

Also, did you try the workaround of setting the ValidateExecutableReferencesMatchSelfContained property to false?

@jamers99
Copy link

Yes this is intentional, we have our tests in our code "compiler check"'d out. We have not tried that option

@dsplaisted
Copy link
Member

I've sent a PR to fix this: #18986

@MatthewSteeples
Copy link

@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

@jamers99
Copy link

@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.

Aaronontheweb added a commit to Aaronontheweb/akka.net that referenced this issue Aug 6, 2021
some .NET 5 SDKs are affected by dotnet/sdk#17579

Added recommended work-around to ensure production of local NuGet packages still
Aaronontheweb added a commit to akkadotnet/akka.net that referenced this issue Aug 6, 2021
some .NET 5 SDKs are affected by dotnet/sdk#17579

Added recommended work-around to ensure production of local NuGet packages still
@jamers99
Copy link

@dsplaisted what is the status of this, do you know when/what versions (.NET 5 and 6) it will be released in?

@dsplaisted
Copy link
Member

It should be in Preview 7 of the .NET 6 SDK.

We don't currently plan to fix it in 5.0 SDKs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

5 participants