15

I've just migrated a (WPF) .NET 4.6 project to .NET 5.

I've noticed it is now creating a folder called 'runtimes' in the output directory with lots of platform-dependent dlls.

Since this app will only run on Windows machines, is there anyway of preventing these folders being created during a build in Visual Studio?

maxp
  • 24,209
  • 39
  • 123
  • 201
  • 2
    I was just fighting a related issue today. Do _not_ just delete the runtimes folder, because then the runtime might pick the assembly in the root folder, which does not have an implementation (every method just throws PlatformNotSupported) – PMF Jun 10 '21 at 20:12

2 Answers2

17

That's pretty easy to change: In your csproj file, inside the PropertyGroup, set the SelfContained property to "false" and specify a RuntimeIdentifier; like this:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
    <SelfContained>false</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
user128440
  • 179
  • 2
  • 7
  • I found this on the runtime identifiers: https://learn.microsoft.com/en-us/dotnet/core/rid-catalog . – Kixoka Jul 15 '22 at 16:00
  • 1
    Thank you, the Output type of WinExe combined with the runtime identifier cleaned up all the unnecessary dll's I was being plagued with. – Reahreic Aug 23 '22 at 15:45
0

The runtime folder contains all the necessary files to run your application regardless your target platform. You can specify to publish a single file, but this is the way the new framework works.

This new way of producing the build artifact may seem counter intuitive. You may have a look at 'runtimes' Folder after Publishing a .Net Core App to Azure Publish Via VS Online

Yennefer
  • 5,704
  • 7
  • 31
  • 44
  • It looks like the app is being published as a 'Self contained deployment' rather than a 'framework dependent deployment', however I see no option to change this? – maxp Jun 10 '21 at 11:45
  • if you choose 'self-contained' then 'Produce single file' you should have a single file. (if I read correctly your comment) – Yennefer Jun 10 '21 at 13:08