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.

msbuild fail : need to set SelfContained to false or UseAppHost to true

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
peterhuenecommented, Aug 30, 2018

I think I see what’s happening here. The reason you do not observe the problem when you specify -r win-x64 to dotnet publish is that the .NET Core SDK defaults both SelfContained and UseAppHost to true when it sees a non-empty RuntimeIdentifier. When the properties from the publish profile are applied, SelfContained is already true and UseAppHost remains true, so there is no error.

However, when you publish without specifying -r win-x64, the .NET Core SDK defaults SelfContained and UseAppHost to false because RuntimeIdentifier is empty. Your publish profile flips SelfContained to true, while UseAppHost 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 of SelfContained changing in a publish profile.

1reaction
peterhuenecommented, Sep 4, 2018

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 in 2.1.400 and I can reproduce the behavior with the older 2.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 specifying UseAppHost in the publish profile will not work.

I’ll investigate the root cause of that behavior. Thanks again for reporting this to us!

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet publish profile CLI vs Visual Studio behave different
Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true.
Read more >
NET SDK error list - .NET CLI
Self-contained applications are required to use the application host. Either set SelfContained to false or set UseAppHost to true. NETSDK1068 ...
Read more >
MSBuild reference for .NET SDK projects
Set the ErrorOnDuplicatePublishOutputFiles property to false if you don't want the error to be generated.
Read more >
need to set SelfContained to false or UseAppHost to true
When I update .net core sdk to 2.1.4, error raised when my project was built to publish.
Read more >
To publish a .NET Core project using the msbuild ...
The SelfContained parameter set to true or false to indicate whether you are publishing for a self-contained or framework-dependent deployment. The ...
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