我正在使用Visual Studio 2013更新4社区版构建Visual Studio程序包/扩展。我正在使用可扩展性项目组下Visual Studio SDK随附的标准项目模板。
我需要的是SVsColorThemeService
但是当我在Initialize方法中添加以下行时
var svc = GetGlobalService(typeof(SVsColorThemeService)) as IVsColorThemeService;
我收到两个构建错误:
Cannot find the interop type that matches the embedded interop type 'Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService'. Are you missing an assembly reference?
Cannot find the interop type that matches the embedded interop type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorThemeService'. Are you missing an assembly reference?
所引用的程序集完全没有被触及。
所以寻找SVsColorThemeService
反编译器就可以找到它
// Decompiled with JetBrains decompiler
// Type: Microsoft.Internal.VisualStudio.Shell.Interop.SVsColorThemeService
// Assembly: Microsoft.VisualStudio.Shell.12.0, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: B8FCA7E4-7D13-4E4B-A74B-6B6B01263DAF
// Assembly location: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.12.0.dll
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
[CompilerGenerated]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[TypeIdentifier]
[Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
[ComImport]
public interface SVsColorThemeService
{
}
}
如您所见,程序集已被引用。因此,问题在于如何掌握SVsColorThemeServie
并正确使用它?
EDIT1: After some research and following the @Simon Mourier suggestion I've added the following code to the solution:
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Microsoft.Internal.VisualStudio.Shell.Interop
{
[ComImport]
[Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface SVsColorThemeService
{
}
[ComImport]
[Guid("EAB552CF-7858-4F05-8435-62DB6DF60684")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IVsColorThemeService
{
IVsColorTheme CurrentTheme { get; }
IVsColorThemes Themes { get; }
void _VtblGap1_4();
void _VtblGap2_1();
}
[ComImport]
[Guid("98192AFE-75B9-4347-82EC-FF312C1995D8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IVsColorThemes
{
IVsColorTheme GetThemeFromId([In] Guid ThemeId);
}
[ComImport]
[Guid("413D8344-C0DB-4949-9DBC-69C12BADB6AC")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IVsColorTheme
{
Guid ThemeId { get; }
void _VtblGap1_1();
void Apply();
}
}
What it does is to provide the missing interfaces for the COM objects. However it still won't build, throwing the same errors + warmings for conflicting types.
Warning 3 The type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorTheme' in 'c:\Users\Codemaster\Documents\Visual Studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs' conflicts with the imported type 'Microsoft.Internal.VisualStudio.Shell.Interop.IVsColorTheme' in 'c:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.Shell.12.0.dll'. Using the type defined in 'c:\Users\Codemaster\Documents\Visual Studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs'. c:\users\codemaster\documents\visual studio 2013\Projects\VSPackage1\VSPackage1\Class1.cs 19 9 VSPackage1
Here is a Link where you can download the sample project: https://drive.google.com/file/d/0B7jBoLH-qaqTV09Mb1VCa3hld1E/view?usp=sharing
Some types in those VS assemblies require other assemblies (PIA). This is explained here: Troubleshooting Errors When Embedding Type Information (Doug Rothaus).
在这种特定于Visual Studio的情况下,除了手动重新创建类型之外,我不知道如何解决(那些程序集在哪里?)(提示:在这种情况下,请使用.NET反射器之类的工具来帮助您,因为DLL确实包含定义)。例如,以下是编译代码的方法,只需将其添加到某处:
namespace MyInterop
{
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
public interface SVsColorThemeService
{
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("EAB552CF-7858-4F05-8435-62DB6DF60684")]
public interface IVsColorThemeService {
void _VtblGap1_4();
IVsColorThemes Themes { [return: MarshalAs(UnmanagedType.Interface)] get; }
IVsColorNames ColorNames { [return: MarshalAs(UnmanagedType.Interface)] get; }
IVsColorTheme CurrentTheme { [return: MarshalAs(UnmanagedType.Interface)] get; }
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("98192AFE-75B9-4347-82EC-FF312C1995D8")]
public interface IVsColorThemes {
[return: MarshalAs(UnmanagedType.Interface)]
IVsColorTheme GetThemeFromId([In] Guid ThemeId);
}
[ComImport, Guid("413D8344-C0DB-4949-9DBC-69C12BADB6AC"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IVsColorTheme {
void _VtblGap1_1();
IVsColorEntry this[ColorName Name] { [return: MarshalAs(UnmanagedType.Interface)] get; }
Guid ThemeId { get; }
}
[ComImport, TypeIdentifier, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("BBE70639-7AD9-4365-AE36-9877AF2F973B")]
public interface IVsColorEntry {
ColorName ColorName { get; }
byte BackgroundType { get; }
byte ForegroundType { get; }
uint Background { get; }
uint Foreground { get; }
}
public struct ColorName {
public Guid Category;
[MarshalAs(UnmanagedType.BStr)]
public string Name;
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("92144F7A-61DE-439B-AA66-13BE7CDEC857")]
public interface IVsColorNames {
void _VtblGap1_2();
int Count { get; }
System.Collections.IEnumerator GetEnumerator();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句