简体   繁体   English

Visual Studio - C# - 具有相同命名空间冲突的多个程序集 - 别名被忽略

[英]Visual Studio - C# - multiple assemblies with same namespace conflict - alias get ignored

I'm working on a Plugin for a software (Revit) using its API (RevitAPI.dll).我正在使用其 API (RevitAPI.dll) 为软件 (Revit) 开发插件。

Some functions in the API have been changed in the latest version 2022 so I'm trying to implement these differences in my code. API 中的某些功能在最新版本 2022 中已更改,因此我正在尝试在我的代码中实现这些差异。

I'm loading the 2020 API with the alias rvt20api and the 2022 as rvt22api - they have the same namespaces inside.我正在使用别名 rvt20api 加载 2020 API,将 2022 加载为 rvt22api - 它们内部具有相同的命名空间。

My problem is that in the 2022 there should be a class called ForgeTypeId but its giving me the CS0234 error (not found) when calling it.我的问题是,在 2022 年应该有一个名为ForgeTypeId的类,但它在调用它时给了我 CS0234 错误(未找到)。

I've opened the RevitAPI.dll (2022) and confirmed that the Class is indeed inside there and if i load just the 2022 API assembly then Visual Studio sees that and is happy but when I load both assemblies then the error.我已经打开了 RevitAPI.dll (2022) 并确认该类确实在其中,如果我只加载 2022 API 程序集,那么 Visual Studio 会看到并且很高兴,但是当我加载两个程序集时就会出现错误。 Seems it's almost reading the rvt20api namespace even tho I'm calling the rvt22api one.似乎它几乎在读取 rvt20api 命名空间,即使我调用的是 rvt22api 命名空间。

在此处输入图像描述

在此处输入图像描述

Short-term question : how do I fix this ?短期问题:我该如何解决这个问题? Am i missing something (not an expert) ?我错过了什么(不是专家)吗?

Long-term question : what is the most appropriate method to go with when working with multiple external api versions?长期问题:使用多个外部 api 版本时最合适的方法是什么? Would it be using the Shared Project approach ?它会使用共享项目方法吗?

Thanks in advance提前致谢

I would suggest creating aliases for each, like so:我建议为每个创建别名,如下所示:

extern alias rvt20api;
extern alias rvt22api;
using rvt20apidb = rvt20api::Autodesk.Revit.DB;
using rvt22apidb = rvt22api::Autodesk.Revit.DB;

// then within the code
var foo = rvt22apidb.forgeTypeId;

Docs on this here .文档在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM