标签: .net-core-publishsinglefile

.NET 5 not compiling to single file executables

Haiya! I'm having an issue regarding trying to compile my .NET 5 application to a single file executable while debugging through Visual Studio.

My CSProject is bellow.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net50</TargetFramework>
    <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

I have my runtime identifier set to winx64 and publish single file set to true, yet when building I'm left with a bunch of DLLs that my application uses building along-side it (a total of 272 in total). I was wondering …

roslyn .net-core .net-core-publishsinglefile asp.net-core-5.0

14
推荐指数
1
解决办法
8918
查看次数

使用 .Net 6 WPF 应用程序的 VS2022 单个 exe 文件进行部署不起作用

我需要在 Windows PC 上执行 .Net WPF 程序的单个 exe 文件。该文件必须使用代码身份验证证书进行签名。有了这个证书,exe 文件就可以在外部 Windows 系统上执行,而无需系统警告或用户将部署复制到受信任位置后的管理权限。

我可以使用 VS2019 和 .Net 4.7.2 来完成此操作。但我想继续使用 VS2022 和 .Net 6.0。下面是一个使用 VS2019 的简单示例。您可以跳过signtool,因为在VS 2022中已经无法创建单个exe文件。VS 2019 和 .Net 5.0 过去也发生过同样的情况,但我找到了一些帖子,其中包含 WPF 的单个 exe 文件将来首先可以与 .Net 6.0 一起使用的信息。现在,在 .Net 6.0 和 VS2022 发布后,我再次尝试。对于单个文件的部署辅助有更多选项可用,但没有任何东西会创建单个 exe 文件!

VS2019中的工作流程:

  • 我使用 .Net Framework 4.7.2 创建 WPF-App(.Net Framework)WPF4Test
  • 我把代码签名命令(“C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x64\signtool.exe”sign /a /n“我的公司名称”/t http:// timestamp构建后步骤中的.comodoca.com/authenticode $(TargetPath))
  • 我在签名过程中构建版本并输入证书密码
  • bin\Release 文件夹包含 3 个文件(WPF4Test.exe、WPF4Test.exe.config、WPF4Test.pdb)
  • 我将 WPF4Test.exe 复制到共享文件夹,并且应用程序可执行并签名

我用.Net 6在VS2022中测试流程

  • 我使用 .Net 6.0 创建 WPF 应用程序 WPF6Test
  • 我将应用程序部署在一个文件夹中(在助手中我必须选择文件夹两次)(默认设置配置发布和目标运行时可移植)
  • 创建 …

deployment wpf .net-core-publishsinglefile .net-6.0 visual-studio-2022

11
推荐指数
2
解决办法
7289
查看次数

附加到 .NET Core 程序时没有符号(单个文件)

为了更好地解释,我将提供一些背景信息。

我有一个在运行时动态加载库的应用程序。该库是某种插件,应用程序旨在测试该插件。

为了能够调试插件,我使用插件项目打开 VS Code,并将调试器附加到已运行且已加载插件的应用程序。插件程序集已构建并具有一个不错的 PDB 文件。

所以工作流程如下:Application => load plugin => attach debugger

首先,即使应用程序已发布,这也是有效的。这是因为加载的插件是在调试中内置的,因此 PDB 就在那里。

但是,在某些情况下,我似乎无法正确附加或未加载符号。这是如果我发布带有该/p:PublishSingleFile=true标志的应用程序的话。在这种情况下,会生成一个文件,当我尝试附加调试器时,它不起作用。

谁能对此提供任何见解?或者一个可能的解决方案?

值得一提的是,我正在使用 .NET 5

干杯

c# .net-core .net-5 .net-core-publishsinglefile

5
推荐指数
1
解决办法
1386
查看次数

如何获取“SelfContained”和“PublishSingleFile”exe 的路径?

我有一个目录,其中包含一个独立的“exe”和一个配置文件。exe 必须读取此配置文件。但问题是exe无法获取这个配置文件的正确路径。

我先说一下我是怎么做到的。

  1. 在VS2019中创建NET5.0项目

在此输入图像描述

  1. 添加代码
using System;
using System.IO;
using System.Reflection;

namespace TestFile {
    class Program {
        static void Main(string[] args) {
            string assemblyLocation = Assembly.GetEntryAssembly().Location;
            Console.WriteLine($"assemblyLocation=\"{assemblyLocation}\"");
            string configFile = Path.Combine((new FileInfo(assemblyLocation)).DirectoryName, "test.conf");
            Console.WriteLine($"configFile=\"{configFile}\"");
            File.ReadAllText(configFile);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 将此项目发布到“SelfContained”和“PublishSingleFile”exe

在此输入图像描述

在此输入图像描述

  1. 在exe所在目录添加test.conf文件

在此输入图像描述

  1. 运行这个exe

在此输入图像描述

我怎样才能得到这个配置文件的正确路径?

c# exe .net-core .net-core-publishsinglefile

3
推荐指数
1
解决办法
2544
查看次数

如何排除将程序集打包到 PublishSingleFile 应用程序中

.NET Core 和 .NET 5 具有单文件可执行功能。

如何排除托管程序集被打包到该单个文件中?

示例:我可能希望app.exe包含MyLib.A.dllMyLib.B.dll,但不包含MyLib.Special.dll。相反,我可能希望它MyLib.Special.dll驻留在旁边的磁盘上app.exe并从那里加载。

(背景:可能是MyLib.Special.dll根据 L-GPL 获得许可的,但是app.exe是专有的。)

.net-core .net-5 .net-core-publishsinglefile

3
推荐指数
1
解决办法
2805
查看次数

.NET 5 MySql TypeInitializationException:从单文件包加载的程序集不支持 CodeBase

如果使用单文件配置发布,应该将数据插入 MySql 数据库的简单控制台应用程序将失败:

    dotnet publish -c Release -r linux-x64 -p:PublishSingleFile=true -o publish/ GarLoader.MySqlUploader
Run Code Online (Sandbox Code Playgroud)

如果我随后运行它 ( ./publish/GarLoader.MySqlUploader),它会失败。堆栈跟踪是:

      System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.Replication.ReplicationManager' threw an exception.
       ---> System.TypeInitializationException: The type initializer for 'MySql.Data.MySqlClient.MySqlConfiguration' threw an exception.
       ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
       ---> System.NotSupportedException: CodeBase is not supported on assemblies loaded from a single-file bundle.
         at System.Reflection.RuntimeAssembly.get_CodeBase()
         at System.Configuration.ClientConfigPaths..ctor(String exePath, Boolean includeUserConfig)
         at System.Configuration.ClientConfigPaths.GetPaths(String exePath, Boolean includeUserConfig)
         at System.Configuration.ClientConfigurationHost.get_ConfigPaths()
         at System.Configuration.ClientConfigurationHost.GetStreamName(String configPath)
         at System.Configuration.ClientConfigurationHost.get_IsAppConfigHttp()
         at System.Configuration.Internal.DelegatingConfigHost.get_IsAppConfigHttp()
         at System.Configuration.ClientConfigurationSystem..ctor()
         at …
Run Code Online (Sandbox Code Playgroud)

.net c# typeinitializationexception .net-5 .net-core-publishsinglefile

3
推荐指数
1
解决办法
1057
查看次数