user6283344
user6283344

Reputation:

How to build App without App.runtimeconfig.json?

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!

Upvotes: 18

Views: 35264

Answers (2)

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

Upvotes: 1

Pavel Anikhouski
Pavel Anikhouski

Reputation: 23288

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

Upvotes: 7

Related Questions