Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

How to deploy a .NET Core 3.x worker service with TeamCity + Octopus?

$
0
0

We are migrating our current .Net Framework services to .NET Core 3.x.
The current deployment pipeline involves the creation of nuget packages using nuget.exe and custom nuspec files.
Then Octopus will install the service on the remote machine.
These nuget packages just contains everything (.nuspec file):

<files>
    <file src="AccountNode.WindowsService\bin\$configuration$\**\*.*"  
exclude="**\*.pdb;**\*.xml" />
  </files>

I wrote the new TeamCity project steps to use dotnet publish, test and pack.
I don't want to use custom nuspec files.
My issue now is that the nuget packages I create does not contain the .exe file, needed to start the webservice.

The project is a Worker Service: <Project Sdk="Microsoft.NET.Sdk.Worker"> and I use the Microsoft.Extensions.Hosting.WindowsServices:

    Host.CreateDefaultBuilder(args)
        .UseWindowsService()

I also use <OutputType>Exe</OutputType> or --runtime --win-x64 so I have I have MyProject.dll and MyProject.exe in bin\Release\netcoreapp3.1\publish when I build with:

dotnet publish MyProject/MyProject.csproj -c Release --runtime win10-x64

Then, I try to create the nuget package with:

dotnet pack    -c Release --no-build MyProject/MyProject.csproj

or

dotnet pack    -c Release MyProject/MyProject.csproj --runtime win10-x64

How to include the .exe file in the nuget package?
packOptions require a project.json file that is not what I want.
So, previously the nuget packages were used just as zip (versioned) files?
Is this approach OK or just using a zip file will be better; I mean, is this the "official way" to deploy a windows service ?


[Update]

I'm using this workaround to reploy the services on the remote server with Octopus.

This is the relevant part in the project file:

<Project Sdk="Microsoft.NET.Sdk.Worker">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>    
        <OutputType>Exe</OutputType>
        <IsPackable>true</IsPackable>
    </PropertyGroup>

    <ItemGroup>    
        <Content Include="bin\Release\netcoreapp3.1\publish\**">
            <Pack>true</Pack>
            <PackagePath>windows-service</PackagePath>
        </Content>
     </ItemGroup>

("**" is required to include "runtimes" folder.)

Practically I'm copying averithing from the "publish" folder into a custom folder ("windows-service"). That folder must include the "runtimes" folder (within the "publish" folder).
On the remote machine Octopus is regitering the servie (sc.exe) passing the path to the .exe inside the "windows-service" folder.

It works and I like that the "dirty" part is just a simple and clear instruction inside the project file but, still, I'm looking for the best practice for this scenario.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>