如何使 Roslyn 又名 MSBuildWorkspace 的行为与 Visual Studio/MSBuild 的行为相同? (又名“ResolveComReferences 问题”)

问题描述 投票:0回答:1

我正在尝试让 Roslyn/MSBuildWorkspace 在一些旧的 .NET Framework 项目上工作。这些偶尔会有 COM 引用,其中一些是不正确的。 在 Visual Studio 中编译会出现警告:

2>------ Rebuild All started: Project: ResolveComReference, Configuration: Debug Any CPU ------
2>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2977,5): warning MSB3284: Cannot get the file path for type library "ffffffff-0000-0000-0000-0000000fffff" version 3.0. Library not registered. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))
2>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2977,5): warning MSB3305: Processing COM reference "VAccessLib" from path "C:\Program Files (x86)\Actian\Zen\bin\ACBtr732.ocx". Type library importer has encountered an interface not derived from IUnknown: 'ISWData'.
2>  ResolveComReference -> C:\ResolveComReference\bin\Debug\ResolveComReference.dll

调用

MSBuild.exe
(不带任何参数)也会编译带有警告的项目,它们显示在详细输出的
ResolveComReferences
部分。

但是从我的代码中执行此操作失败了(代码是通常的:

workspace = MSBuildWorkspace.Create(); var solution = await workspace.OpenSolutionAsync(solutionPath);
)。

Msbuild failed when processing the file 'C:\ResolveComReference\ResolveComReference.csproj' with message: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets: (2977, 5): The "ResolveComReference" task could not be instantiated from "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Could not load file or assembly 'Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Msbuild failed when processing the file 'C:\ResolveComReference\ResolveComReference.csproj' with message: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets: (2977, 5): The "ResolveComReference" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.

另外还有一个项目参考

Found project reference without a matching metadata reference: C:\TestProjects\_EmptyProject48\code.csproj

所有这一切都是使用项目模板“独立代码分析工具”中的代码发生的。更新引用的 nuget 包没有帮助。

如何让它发挥作用?

认为我可以通过在任何地方使用

AdhocWorkspace
并手动解析sln和csproj文件来解决这个问题(请参阅LegacyWorkspaceLoader),但我真的不愿意,特别是因为我see
MSBuild.exe
按预期工作在相同的解决方案上。

COM 示例参考项目:

    <COMReference Include="some_unexisting_library">
      <Guid>{FFFFFFFF-0000-0000-0000-0000000FFFFF}</Guid>
      <VersionMajor>3</VersionMajor>
      <VersionMinor>0</VersionMinor>
      <Lcid>0</Lcid>
      <WrapperTool>aximp</WrapperTool>
      <Isolated>False</Isolated>
    </COMReference>
.net msbuild roslyn roslyn-code-analysis
1个回答
0
投票

对于遇到此类问题的任何人,请尝试升级到 Roslyn 软件包的 4.9.0-2.final 版本; MSBuildWorkspace 在该版本中已发生重大更改,现在应该避免类似的问题。

© www.soinside.com 2019 - 2024. All rights reserved.