【问题标题】:New .NET Core SDK Project Type - Debug COM Add-in not possible?新的 .NET Core SDK 项目类型 - 无法调试 COM 插件?
【发布时间】:2019-11-14 19:07:24
【问题描述】:

我最近在一个旧项目上升级到 .NET Framework 4.8,并认为我发现了 Visual Studio 2019 调试器和/或新的 .NET Core SDK 项目类型的限制。

下面是csproj的前后对比:

之前

ExcelAddin.MyRtdServer.csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{572DAC9C-DC52-425A-83F2-6EF0EB4FF2BC}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AssemblyName>ExcelAddin.MyExcelRtdServer</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <ApplicationVersion>1.0.0.0</ApplicationVersion>
    <FileAlignment>512</FileAlignment>
    <RootNamespace>ExcelAddin.MyExcelRtdServer</RootNamespace>
    <FileUpgradeFlags>
    </FileUpgradeFlags>
    <UpgradeBackupLocation>
    </UpgradeBackupLocation>
    <OldToolsVersion>3.5</OldToolsVersion>
    <TargetFrameworkProfile />
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
    <RegisterForComInterop>true</RegisterForComInterop>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <Prefer32Bit>false</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup>
    <SignAssembly>true</SignAssembly>
  </PropertyGroup>
  <PropertyGroup>
    <AssemblyOriginatorKeyFile>MyStrongName.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
      <HintPath>..\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data.Linq" />
    <Reference Include="System.Data" />
    <Reference Include="System.Core" />
    <Reference Include="System.Configuration" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="..\GlobalAssemblyInfo.cs">
      <Link>Properties\GlobalAssemblyInfo.cs</Link>
    </Compile>
    <Compile Include="MyRtdServer.cs" />
    <Compile Include="Properties\Settings.Designer.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
    <None Include="packages.config" />
    <None Include="MyStrongName.snk" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

ExcelAddin.MyRtdServer.csproj.user

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files %28x86%29\Microsoft Office\root\Office16\EXCEL.EXE</StartProgram>
  </PropertyGroup>
  <PropertyGroup>
    <ProjectView>ShowAllFiles</ProjectView>
  </PropertyGroup>
</Project>

之后

ExcelAddin.MyRtdServer.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net48</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
  </PropertyGroup>
  <PropertyGroup>
    <Authors>John Zabroski</Authors>
    <Description>ExcelAddin.MyExcelRtdServer .NET Assembly</Description>
    <Copyright>Copyright © 2019</Copyright>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>MyStrongName.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="appSettings.xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="..\GlobalAssemblyInfo.cs" Link="Properties\GlobalAssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="appSettings.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Office.Interop.Excel" Version="15.0.4795.1000" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="System.Configuration" />
    <Reference Include="System.Data.Linq" />
  </ItemGroup>
</Project>

launchSettings.json

{
  "profiles": {
    "ExcelAddin.MyRtdServer": {
      "commandName": "Executable",
      "executablePath": "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE"
    }
  }
}

【问题讨论】:

  • 不支持注册加载项。痛苦。所以你忘了用手做吗?
  • 我使用 RegAsm.exe /tlb 和 /codebase 手动注册了加载项。假设我正确地进行了普通的簿记。
  • 我想RegAsm.exe /unregister my.dll 可能是错误的,因为之前在bin/Debug/bin/Debug/net48/ 下注册。我会对此进行更多研究。

标签: c# com visual-studio-debugging visual-studio-2019 excel-addins


【解决方案1】:

Excel-DNA 目前不支持新的 SDK 样式项目,我们正在努力增加对即将推出的 Excel-DNA 版本的支持。

您可以跟踪以下问题以获取有关该方面进展的通知:

【讨论】:

  • 我更一般地询问在这些条件下的调试。我怀疑一旦你解决了那些与调试无关的其他问题,你就会遇到这个一般的可调试性问题。
  • @JohnZabroski 我没有看到任何调试问题。主要区别在于您如何告诉 VS2019 查找 EXCEL.EXE(launchSettings.json 而不是 Project.csproj.user),这就是为什么 Excel-DNA 构建 SetDebuggerOptions 目前不适用于 SDK 样式的项目
  • 我更新了问题以证明即使正确设置了 launchSettings.json 和 Project.csproj.user,问题仍然存在。
  • 他使用 Microsoft.Office.Interop.Excel,这听起来不太像 DNA。
  • 我实际上在一个遗留项目中有多种变体。一种方法使用 DLL。我可能应该清理它并完全删除对该 DLL 的引用,只使用 COM 接口。
猜你喜欢
  • 2017-04-27
  • 2011-10-24
  • 2016-11-18
  • 1970-01-01
  • 2017-12-19
  • 1970-01-01
  • 2013-04-25
  • 1970-01-01
  • 2020-06-27
相关资源
最近更新 更多