当引用COM对象ActiveD或MSXML2时,会出现很多构建警告 [英] Lots of build warnings when COM objects ActiveDs or MSXML2 are referenced

查看:257
本文介绍了当引用COM对象ActiveD或MSXML2时,会出现很多构建警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将项目从.NET 1.1迁移到.NET 2.0之后,MsBuild会针对某些COM对象发出很多警告.

After moving a project from .NET 1.1 to .NET 2.0, MsBuild emits lots of warnings for some COM objects.

用于测试的示例代码(实际的代码无关紧要,仅用于创建警告):

Sample code for test (actual code doesn't matter, just used to create the warnings):

using System;
using System.DirectoryServices;
using ActiveDs;
namespace Test
{
    public class Class1
    {
        public static void Main(string[] args)
        {
            string adsPath = String.Format("WinNT://{0}/{1}", args[0], args[1]);
            DirectoryEntry localuser = new DirectoryEntry(adsPath);
            IADsUser pUser = (IADsUser) localuser.NativeObject;
            Console.WriteLine("User = {0}", pUser.ADsPath);
        }
    }
}

警告消息看起来像

C:\ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ Microsoft.Common.targets:警告:运行时封送程序无法封送'ITypeLib.RemoteGetLibAttr'的至少一个参数.因此,此类参数将作为指针传递,并且可能需要使用不安全的代码进行操作.

观察:

  • 发生ActiveD(11个警告)和MSXML2(54个警告).
  • 没有看到我们自己的COM对象.
  • .csproj文件中的
  • <Reference>条目包含属性WrapperTool = "tlbimp"
  • 尽管有所有警告,但在运行的系统中未发现任何问题.
  • Happens for ActiveDs (11 warnings) and MSXML2 (54 warnings).
  • Not seen for our own COM objects.
  • <Reference> entry in .csproj file contains attribute WrapperTool = "tlbimp"
  • Despite of all warnings, no problems have been observed in the running system.

有什么想法摆脱警告吗?

Any idea how to get rid of the warnings?

推荐答案

根据

According to a comment in the MDSN article about TLBIMP for 2.0, you can't fix this problem w/o running TLBIMP yourself.

使用VS可以很容易地重现您的问题.我还从VS注释提示符下手动运行TLBIMP来重现它:

It was easy to reproduce your problem using VS. I also reproduced it running TLBIMP manually from a VS comment prompt:

   tlbimp c:\WINNT\system32\activeds.tlb /out:interop.activeds.dll

解决方法是使用/silent开关

The fix was to use the /silent switch

   tlbimp c:\WINNT\system32\activeds.tlb /silent /out:interop.activeds.dll

如MSDN文章中的注释所指出,COM引用将成为您自己构建的互操作程序集的.n​​et程序集引用.

As pointed out in the comment in the MSDN article, the COM reference becomes a .net assembly reference to the interop assembly you built yourself.

我不是VS专家,但是我通过向以下项目添加预构建来完成这项工作:

I'm not a VS expert, but I made this work by adding a prebuild to project of:

    "$(DevEnvDir)\..\..\SDK\v2.0\bin\tlbimp" c:\WINNT\system32\activeds.tlb
            /namespace:ActiveDs /silent /out:"$(ProjectDir)interop.activeds.dll"

将其构建一次,这样我就可以使用dll在浏览"选项卡中添加引用.在我的项目根目录中添加了对interop.activeds.dll的引用,然后重新构建.您可能希望以其他方式执行此操作,例如通过C ++项目使用外部make文件.这更像是一个POC.

Built it once so I'd have a dll to add a reference with the browse tab. Added a reference to the interop.activeds.dll in my project root and then built again. You may want to do this some other way, like with an external make file via a C++ project. This is more of a POC.

请注意,MSBUILD与VS有一个有趣的区别,$(DevEnvDir)带一个反斜杠,而MSBUILD没有.

Note a funny difference in MSBUILD vs VS, $(DevEnvDir) has a trailing backslash but MSBUILD does not.

这篇关于当引用COM对象ActiveD或MSXML2时,会出现很多构建警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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