Kaizer69
Kaizer69

Reputation: 432

How to execute framework-dependent deployment using dotnet publish with remote host

We have a continuous build going on and are trying to publish a dotnet core app as a windows service. We can do this using visual studio with the following publish profile

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <PublishProvider>FileSystem</PublishProvider>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <ProjectGuid>d655df5a-9266-470d-becd-6d62c919e961</ProjectGuid>
    <SelfContained>false</SelfContained>
    <_IsPortable>true</_IsPortable>
    <publishUrl>C:\publish\webapi</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
  </PropertyGroup>
</Project>

At first we tried the path of least resistance and tried to call dotnet publish project /p:PublishProfile=<FolderProfileName>

This command ignored the publish profile settings so we fell back on manually setting the properties. This however, would only build either a self-contained app with an exe but all the net core dlls or a framework dependent app with just dlls

Command executed

dotnet publish Project.csproj -c "Release" -o "C:\Publish\App" -r "win-x64" --self-contained false

Question is how can I mimic the VS2017 Publish of net core apps using the publish profile since I hit the problems I specified above.

Target output would be to publish the net core app without the aspnetcore dlls but with a remote host executable.

Upvotes: 3

Views: 5345

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100741

The publish profile is meant to be used along with the build, by passing

-p:DeployOnBuild=true -p:PublishProfile=<ProfileName>

to dotnet build or msbuild. This is the same as "classic" ASP.NET projects.

If you only need filesystem deployments, you can use dotnet publish instead which can directly create publish outputs to target locations (web deploy uses the same mechanisms internally by publishing to a temporary location and then copying, zipping etc.).

dotnet publish will create a self-contained deployment automatically when passed a runtime identifier (-r option).

If you also want a host exe to boot up the runtime, you can also use

dotnet publish -r win-x64 --self-contained false -p:UseAppHost=true

to emit a .exe file that you can use as windows service instead of path\to\dotnet.exe path\to\app.dll, which will still use the machine-wide .NET Core install. This may or may not become part of the default output in 3.0.

Upvotes: 6

Related Questions