msbuild fail : need to set SelfContained to false or UseAppHost to true
See original GitHub issueWhen I update .net core sdk to 2.1.4, error raised when my project was built to publish.
C:\Program Files (x86)\dotnet\sdk\2.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(122,5): error NETSDK1067: Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true. [C:\Program Files (x86)\Jenkins\workspace\TMQ4.DEV\Tmq.Web\Tmq.Web.csproj]
My publication Profile.pubxml is like below:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://10.201.248.21:6063</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<ProjectGuid>395ae9e5-cc25-4e6d-90c3-7eb056d30a9f</ProjectGuid>
<MSDeployServiceURL>10.200.248.21</MSDeployServiceURL>
<DeployIisAppPath>TMQ4</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>False</EnableMSDeployBackup>
<UserName>10011531</UserName>
<_SavePWD>False</_SavePWD>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
<SelfContained>true</SelfContained>
<_IsPortable>false</_IsPortable>
</PropertyGroup>
</Project>
The profile.pubxml was created by visual studio with publication gui config.
When I add item
<UseAppHost>true</UseAppHost>
to PropertyGroup, It was fine.
1、When was it be introduced?
2、Who can show detail about UseAppHost ?
3、Is it conflict with SelfContained, I think SelfContained Setting is enough?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (8 by maintainers)
Top GitHub Comments
I think I see what’s happening here. The reason you do not observe the problem when you specify
-r win-x64
todotnet publish
is that the .NET Core SDK defaults bothSelfContained
andUseAppHost
to true when it sees a non-emptyRuntimeIdentifier
. When the properties from the publish profile are applied,SelfContained
is already true andUseAppHost
remains true, so there is no error.However, when you publish without specifying
-r win-x64
, the .NET Core SDK defaultsSelfContained
andUseAppHost
to false becauseRuntimeIdentifier
is empty. Your publish profile flipsSelfContained
to true, whileUseAppHost
remains false. The .NET Core SDK later notices this during publishing and errors.This is an unfortunate regression that did not take into account users that would be setting
SelfContained
to true in a publish profile.The best workaround for you is to also set
UseAppHost
to true in your publish profile. This property, which was introduced in the 2.1.400 version of the .NET Core SDK, controls whether or not a native executable will be created for your deployment, which is required for self-contained deployments.I’ll see if there’s a way we can fix this, such as checking to see if
UseAppHost
, when defaulted, should be defaulted again as a result ofSelfContained
changing in a publish profile.Hi @TimRowe,
Thanks for the repro project. I can confirm the behavior you’re seeing, although it does not appear to be a regression related to the
UseAppHost
change itself, as that was introduced in2.1.400
and I can reproduce the behavior with the older2.1.302
SDK.I am seeing
apphost.exe
appear, but it has not been renamed, nor does it seem to have had the path to the application embedded.I think the publish profile is being applied “too late” for logic in the SDK to respect it properly.
A workaround for now is to pass the runtime to the publish command (i.e.
-r win-x64
), which should cause the project to publish self-contained with an apphost, as expected. Because of the above behavior, my previously suggested workaround of specifyingUseAppHost
in the publish profile will not work.I’ll investigate the root cause of that behavior. Thanks again for reporting this to us!