Facing issues for the mismatch definitions of some methods from SQLEditors.dll used in SSMS 21

Vaibhav Pol 15 Reputation points
2025-01-06T06:11:18.7833333+00:00

I am trying to consume the SQLEditors.dll from SSMS 21 and SSMS20 in my C# code however getting the compilation issue due to incorrect format of library as
error : D:\BuildAgentB\work\fb305f1670873990\VersionSpecific.CommonFiles\NewQueryWriter.cs(83, 29): error CS0012: The type ‘IVsProject’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘Microsoft.VisualStudio.Interop, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

This is because in SSMS 21 SQLEditor.Dll has CreateNewScript defined like public object CreateNewScript(string strFullPathToScript, IVsProject projectToAddScriptTo, Microsoft.SqlServer.Management.Smo.RegSvrEnum.UIConnectionInfo ci, System.Data.IDbConnection liveCon, string rootName) Member of Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptFactory

where as in SSMS 20 SQLEditors.dll has the definition public object CreateNewScript(string strFullPathToScript, Microsoft.VisualStudio.Shell.Interop.IVsProject projectToAddScriptTo, Microsoft.SqlServer.Management.Smo.RegSvrEnum.UIConnectionInfo ci, System.Data.IDbConnection liveCon, string rootName) Member of Microsoft.SqlServer.Management.UI.VSIntegration.Editors.ScriptFactory

Here second parameter has i.e. IVsProject has prefix with proper/expected class library which is missing in SSMS21 dll which causes issue. There are many other class method definitions like CreateNewScript, RegisterPriorityCommandTarget, etc which has similar issue.

Adding/upgrading Microsoft.VisualStudio.Interop package will not work as there are other dependencies on old code and the some code is common in both SSMS 20 and 21. Could someone help on this or is there any plan to update the SSMS 21 SQLEditor.Dll.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
4,041 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,289 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,195 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Hongrui Yu-MSFT 3,730 Reputation points Microsoft Vendor
    2025-01-08T09:34:44.9833333+00:00

    Hi, @Vaibhav Pol.

    You could use different versions of Microsoft.VisualStudio.Shell.Interop in the same project through Aliases.

    Assuming you have installed version 7.10.6071 of Microsoft.VisualStudio.Shell.Interop via NuGet

    Picture1

    Only the following code requires version 17.0.0.0 of Microsoft.VisualStudio.Shell.Interop

    var newWindow = factory.CreateNewScript(string.Empty, externalProject, connection, null, string.Empty);
    

    You could do the following: Just like adding SQLEditor.Dll, find Microsoft.VisualStudio.Interop.dll in ~Program Files\Microsoft SQL Server Management Studio 21\Preview\Common7\IDE\Remote Debugger\x64\ on your computer and add it(If the dll location of Microsoft.VisualStudio.Shell.Interop 17.0.0.0 is different, you could adjust it yourself)

    Open Properties

    Picture2

    Enter Aliases

    Picture3

    Using Aliases

    Picture4

    Test results

    Picture5

    You could also find Microsoft.VisualStudio.Shell.Interop 7.10.6071 in Packages in the same way and get an Aliases for it

    More about Aliases :https://zcusa.951200.xyz/en-us/dotnet/csharp/language-reference/keywords/extern-alias


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.