尽管使用 DebugType=None,Visual Studio 发布仍会生成 .pdb 文件 [英] Visual Studio publish generates .pdb file despite using DebugType=None

查看:56
本文介绍了尽管使用 DebugType=None,Visual Studio 发布仍会生成 .pdb 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下发布配置文件从 Visual Studio 中发布控制台应用程序:

I'm publishing a console app from within Visual Studio using the following publish profile:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <PublishProtocol>FileSystem</PublishProtocol>
    <Configuration>Release</Configuration>
    <Platform>x64</Platform>
    <TargetFramework>netcoreapp5.0</TargetFramework>
    <PublishDir>bin\Release\netcoreapp5.0\publish\</PublishDir>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
    <SelfContained>False</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>True</PublishReadyToRun>
    <IncludeNativeLibrariesForSelfExtract>True</IncludeNativeLibrariesForSelfExtract>

    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
  </PropertyGroup>
</Project>

我的目标是不在发布输出文件夹中发出任何 .pdb 文件(调试符号).
这并不完全按预期工作.

My goal is to not emit any .pdb files (debug symbols) in the publish output folder.
This doesn't completely work as intended.

控制台应用程序项目的 .pdb 文件未按预期生成,但它引用的业务逻辑项目的调试符号由于某种原因生成.这是一个错误吗?

The .pdb file of the console app project is not generated - as expected, but the debug symbols for the business logic project it references is for some reason generated. Is this a bug?

我可以通过向业务逻辑库的项目文件添加条件语句来解决这个问题,但这是我想避免的,因为我认为发布应用程序的所有相关信息都应位于发布配置文件中.

I can hack this by adding a conditional statement to the project file of the business logic library, but that it something I'd like to avoid as I think all the relevant information for publishing the app should reside in the publish profile.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
   <DebugType>none</DebugType>
   <DebugSymbols>false</DebugSymbols>
</PropertyGroup>

推荐答案

nonefalse 只会阻止生成当前项目的 pdb 文件.如果您的主项目引用了第二个项目,这些节点将不会阻止主项目中第二个项目的 pdb 文件.这是由那个设计的.

<DebugType>none</DebugType><DebugSymbols>false</DebugSymbols> will only prevent the generation of the current project's pdb file. And if your main project referenced a second project, these nodes will not prevent the the second project's pdb file in the main project. This is designed by that.

并且如果要防止引用项目的pdb文件生成到主项目的发布文件夹中,则应另外使用此节点:

And if you want to prevent the referenced project's pdb file being generated into the publish folder of the main project, you should use this node additionally:

<AllowedReferenceRelatedFileExtensions>*.pdb</AllowedReferenceRelatedFileExtensions>

解决方案

将这些添加到您的 pubxml 文件中:

Add these in your pubxml file:

<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<AllowedReferenceRelatedFileExtensions>*.pdb</AllowedReferenceRelatedFileExtensions>

这篇关于尽管使用 DebugType=None,Visual Studio 发布仍会生成 .pdb 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆