gpt4 book ai didi

c# - 调试器尝试使用错误的程序集名称启动程序集

转载 作者:太空宇宙 更新时间:2023-11-03 12:38:11 25 4
gpt4 key购买 nike

我有带有 Visual Studio 2010 的 C# 应用程序。我想要每个配置的程序集名称。也就是说,我需要不同的程序集名称来进行调试和发布配置。所以我编辑了我的 csproj 如下。

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<...>
<...>
</PropertyGroup>
<Choose>
<When Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<PropertyGroup>
<AssemblyName>MyApplication</AssemblyName>
</PropertyGroup>
</When>
<When Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<PropertyGroup>
<AssemblyName>MyApplicationd</AssemblyName>
</PropertyGroup>
</When>
</Choose>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<...>
<OutputPath>..\..\..\..\utils\debug\Project\x64\</OutputPath>
<...>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<...>
<OutputPath>..\..\..\..\utils\release\Project\x64\</OutputPath>
<...>
</PropertyGroup>
</Project>

构建成功,我得到了用于发布配置的 MyApplication.exe 和用于调试配置的 MyApplicationd.exe。但是当我 F5/F10 在 Debug模式下运行项目时,出现以下错误。

Visual Studio cannot start debugging because the debug target is missing. Please build the project and retry, or set the OutputPath and AssemblyName properties appropriately to point at the correct location for the target assembly.

我该如何解决这个问题?如何根据项目文件中的配置指定不同的程序集名称?

最佳答案

应该不是输出路径的问题,我觉得应该是程序集的名字有关。

我的理解是你得到了详细的错误列表:

“Visual Studio 无法启动调试,因为缺少调试目标“xxx\xxx\MyApplication”(注意:不是 MyApplicationd)。我说得对吗?

右键单击您的项目->属性->应用程序,如果您检查程序集名称,我的理解是它是发布名称“MyApplication”的名称。如果你真的想在 Debug模式下调试它,这个属性的名称需要是“MyApplicationd”,当然,如果你使用调试程序集名称, Release模式将不起作用。

我的理解是,我们可以在项目属性中编辑 UI 程序集名称,然后在您的 .xxproj 文件中生成 xml 代码,但是如果您直接编辑 proj 文件,它不会在 UI 下自动更改它。

我这里也是这样用的:

Change assembly name based on configuration (Visual Studio 2005/2008)

但是它有和你一样的错误信息。

你的使用方式好像和MSBuild命令行有关:

Change name of exe depending on conditional compilation symbol

enter image description here

关于c# - 调试器尝试使用错误的程序集名称启动程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40122521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com