11

When I publish my .NET Core app, it outputs a runtimes directory with the following sub-directories:

- publish/runtimes/
   - debian.8-x64/
   - fedora.23-x64/
   - fedora.24-x64/
   - opensuse.13.2-x64/
   - opensuse.42.1-x64/
   - osx/
   - osx.10.10-x64/
   - rhel.7-x64/
   - ubuntu.14.04-x64/
   - ubuntu.16.04-x64/
   - ubuntu.16.10-x64/
   - unix/
   - win/

On my CI/CD server I publish my applications with this command:

dotnet publish -c Release -o ..\publish

My publish settings in the project file are the following:

  • Target Framework: netcoreapp2.1
  • Deployment Mode: Framework-Dependent
  • Target Runtime: win-x64

I only plan to publish this application on Windows 2016 Server so the OSX/Linux/Unix runtimes folders are not necessary. Worse in several cases these runtimes folders contain known vulnerable dlls which lead to false positive OSA scans.

Is there a way to configure the project to only output the win runtime folder?

Update

I have tried the suggestions by @ahsteele and the output of adding the RIDs to my csproj files is the same as if I did not specify the RIDs.

When I run CI/CD command example

dotnet publish -c Release -r win10-x86 -o ..\publish

I believe it creates a self-contained deployment. As my publish directory goes from being 55MB to 120MB and from 237 files to 482 files.

Update 2

I have tried specifying my startup project for the publish step and it builds the run time directories to be more compact.

Here is the build command I am running:

dotnet publish .\startupProject.csproj -c Release -o ..\publish

And this is the output:

- publish/runtimes/
   - unix/
   - win/

Some of the projects in my solution do specify netstandard2.0 and some specify netcoreapp2.0. Does Microsoft document anywhere that if you don't specify a target framework or a specific csproj file, it will give you all of the target frameworks for all of the possible runtimes?

Nick
  • 978
  • 1
  • 12
  • 28
  • Can you share your csproj file? Can you reproduce this with a simpler project (less code, but similar csproj file)? Is there a `RuntimeIdentifiers` setting in your project file? – omajid Nov 27 '18 at 20:04
  • @omajid There are no `RuntimeIdentifiers` in any of the project files for the solution. Let me see if I can get something. – Nick Nov 27 '18 at 20:08
  • @omajid I tried creating a simple project and it does now show this behavior. I'll keep trying to add complexity to see if I can duplicate this. Thanks! – Nick Nov 28 '18 at 22:18
  • Self-contained deployment requires `--self-contained` switch, which you never use. – Lex Li Nov 29 '18 at 03:37
  • @LexLi I modified the command to include the `dotnet publish -c Release -o ..\publish-selfcontained -r win10-x86 --self-contained` and its output is the same as if I did not include the `--self-contained` flag. 482 Files and 120MB. – Nick Nov 29 '18 at 15:17

1 Answers1

4

You should be able to specify your runtime with the dotnet publish -r switch. From the .NET Core RID Catalog - Windows RIDs the Windows 10 / Windows Server 2016 RIDs are:

  • win10-x64
  • win10-x86
  • win10-arm
  • win10-arm64

Meaning that your CI/CD command can specify the runtime:

dotnet publish -c Release -r win10-x86 -o ..\publish

Alternatively a single RID can be set in the <RuntimeIdentifier> element of your project file:

<RuntimeIdentifier>win10-x64</RuntimeIdentifier>

Multiple RIDs can be defined as a semicolon-delimited list in the project file's <RuntimeIdentifiers> element:

<RuntimeIdentifiers>win10-x64;win10-x86</RuntimeIdentifiers>
ahsteele
  • 26,243
  • 28
  • 134
  • 248
  • Thanks! I tried adding the RIDs to my csproj files and it did not change the output of the runtime directory. I ran the CI/CD command in your example and it doubled the size of the publish directory compared to no RID specified. It removed the runtime directory and looks like it is now a self contained deployment with a lot of Microsoft DLLs. – Nick Nov 28 '18 at 22:16