16

When I build the App in Release mode in Visual Studio it generates these files in Release folder:

App.exe 
App.dll 
App.runtimeconfig.json 
App.pdb
App.deps.json
App.runtimeconfig.dev.json

If I move the first 3 files location and double click the App.exe it starts. If I delete App.runtimeconfig.json it doesn't start!

I want to keep only App.exe and App.dll in my folder, what do I have to do to get rid of that App.runtimeconfig.json?


EDIT #1

Here's the content of App.runtimeconfig.json:

{
  "runtimeOptions": {
    "tfm": "netcoreapp3.0",
    "framework": {
      "name": "Microsoft.WindowsDesktop.App",
      "version": "3.0.0"
    }
  }
}

EDIT #2

Here's what I've now in my App.csproj file's PropertyGroup:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishReadyToRun>true</PublishReadyToRun>
    <PublishSingleFile>true</PublishSingleFile>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <UseWPF>true</UseWPF>
</PropertyGroup>

now I get this in Error List of Visual studio:

Error NETSDK1047 Assets file 'C:\Users\Emon\source\repos\SocketTest\App\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers. App C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 234

When I right click on Project I see: Build, Clean, Rebuild, etc., there's no restore!


EDIT #3

I've deleted the bin and obj folders first and reordered the <PropertyGroup> to put the <RuntimeIdentifier> beneath the <TargetFramework>, now it works!

Peter Csala
  • 17,736
  • 16
  • 35
  • 75
  • 1
    What is the content of file? It contains runtime information and used .NET core version. You try to switch to self contained deployment – Pavel Anikhouski Nov 22 '19 at 13:27
  • @PavelAnikhouski, edited my post and added the content. How to deploy as `self contained` in visual studio? If you don't mind post the process in answer section please. –  Nov 22 '19 at 13:30

2 Answers2

6

As you can see, App.runtimeconfig.json contains the runtime information and used .NET Core version, you can't simply delete it. But you switch to self contained deployment by selecting Self-contained deployment mode when publish the app

.NET Core introduced the ability to trim the result executable to reduce size. Basically, you need the following properties in your project file

<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>

There is a very nice article about single executables

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
  • 1
    But `RuntimeIdentifier` is here:) Please, ensure that you are using it correctly and not using the `RuntimeIdentifiers` in plural form – Pavel Anikhouski Nov 22 '19 at 14:08
  • Yes I missed that last time, But this time I've included that line and now I get another error. I've updated the post to show What I've done in csproj and the error –  Nov 22 '19 at 14:15
  • 1
    Look at this [GitHub thread](https://github.com/dotnet/sdk/issues/1321) – Pavel Anikhouski Nov 22 '19 at 14:25
  • Yes, now it works, I just have to have all the required `dll` and `exe`, nothing else. –  Nov 22 '19 at 15:22
  • 3
    For my reference, If I want a single `exe`, without any `.dll`, I've to click on `Publish` instead of `Build`, great! –  Nov 23 '19 at 16:59
0

I wanted to keep my csproj file as generic as possible and didn't want to specify any RuntimeIdentifiers in that file. I would rather specify the RuntimeIdentifier as a command line build option. This is what I came up with:

csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
        <OutputType>Exe</OutputType>
        <Platforms>AnyCPU;x64</Platforms>
        <PublishReadyToRun>true</PublishReadyToRun>
        <PublishSingleFile>true</PublishSingleFile>
        <PublishTrimmed>true</PublishTrimmed>
        <TargetFramework>net5.0</TargetFramework>
    </PropertyGroup>
</Project>

Command line:

dotnet publish --runtime win-x64 -c Release
James John McGuire 'Jahmic'
  • 11,728
  • 11
  • 67
  • 78