ExtensionManager null in Visual Studio 2017 - c#

In previous versions of Visual Studio I could use the following code to retrieve information about a certain installed extension (vsix):
IVsExtensionManager manager = ServiceProvider.GlobalProvider.GetService(typeof(SVsExtensionManager)) as IVsExtensionManager;
if (manager != null)
{
VsExtension extension = new VsExtension();
IInstalledExtension info = manager.GetInstalledExtension(cExtensionProductId);
}
In the new Visual Studio 2017 version, the 'manager' variable is always null. Microsoft changed the way to retrieve the information (they no longer use the system registry), but I can't find another way to retrieve the info.
Do you know where I can find more information and/or provide a sample of the new implementation?
Thank you in advance!

Please check that for VS 2017 you are using VS 2017 specific references to the extension manager. It should be Microsoft.VisualStudio.ExtensionManager.dll and
Microsoft.VisualStudio.ExtensionEngine.dll.
For a working example see https://vlasovstudio.com/visual-commander/commands.html#ExtensionsList.

Is the ServiceProvider.GlobalProvider.GetService(typeof(SVsExtensionManager)) returns null ? or "as IVsExtensionManager" becomes null ?

Related

Managed Package Framework for Visual Studio 2017

I'm following this tutorial on how to create a new Visual Studio Project type. In there, it says to "Import the source-code files for the Managed Package Framework". Google led me to this link that has a link to MPF 2013 package. In the first link they say to look for a file ProjectBase.files which does not exist in the second link download.
Questions:
Where is the correct MPF download for Visual Studio 2017.
In the future when we move on to Visual Studio 2019, will I need to download a new MPF for 2019?
I had the same problem, but it seems that I alreasy solved it. It seems that MPF is not needed anymore to do these steps and the tutorial is a bit outdated:
How to do it now:
Instead of loading the "Managed Package Framework code", skip this whole step in the tutorial and go to the next chaprer.
In the next chapter skip everything until step 3 and register
this.RegisterProjectFactory(new SimpleProjectFactory(this));
in the InitializeAsync Task of the SimpleProjectPackage.cs
At step 6 implement FlavoredProjectFactory instead of ProjectFactory
Continue the tutorial and it should work fine now.
In the end it should look like this:
class SimpleProjectFactory : FlavoredProjectFactory
{
private SimpleProjectPackage simpleProjectPackage;
public SimpleProjectFactory(SimpleProjectPackage simpleProjectPackage)
{
this.simpleProjectPackage = simpleProjectPackage;
}
protected override object PreCreateForOuter(object outerProject)
{
return null;
}
}

Visual Studio Online CI daily builds fail since switching to VS 2015 and using C# 6 Roslyn features

Since switching from VS 2013 to VS 2015 and using some new C# 6 features, our daily builds in Visual Studio Online have begun failing.
The errors on the build are all pointing to the new auto property feature but I assume all new features will cause this.
An example piece of code that causes a failure is using:
public int MyFavouriteNumber { get; set; } = 7;
instead of
private int _myFavouriteNumber = 7;
public int MyFavouriteNumber
{
get { return _myFavouriteNumber; }
set { _myFavouriteNumber = value; }
}
I've had a look around my build configuration, but I can't see anything that relates to C# 6 or Roslyn.
What do I have to change to make my daily builds work again?
Edit
Here's an example error (they're all the same, for auto properties).
Models\Core\Bookings\BookingProduct.cs (29, 0)
Invalid token '=' in class, struct, or interface member declaration
Models\Core\Bookings\BookingProduct.cs (29, 0)
Invalid token '(' in class, struct, or interface member declaration
And here is the offending line:
public virtual IList<BookingPricingAddon> AddonsPricing { get; set; } = new List<BookingPricingAddon>();
TheLethalCoder's comments pointed me in the right direction.
The problem was that all of my projects were using Default as the target Language Version, which is fine if you're using VS 2015, however, my .sln file had the following opening 3 lines:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
Apparently, Visual Studio Online uses this to work out which version of MSBuild to use. (It was using 12).
Upgrading my solution to the following:
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
allowed Visual Studio Online to see that my IDE was using Roslyn, and therefore used MSBuild 14.
The easiest way I found to upgrade is to click on the solution in Solution Explorer and then going to File > Save As > Solution File and overwrite your existing solution file, it just upgrades the first 3 lines.
My builds are now successful.
I think the same could be achieved by setting the Language Version on each of your projects. This can be done by going to your .csproj files and navigating to:
Properties > Build > Advanced > Language Version > C# 6.0
A good reference about the Default settings in each IDE can be found here.

Where to get Windows.VisualStudio.Data?

Hello I'm am beginning with visual studio and C#
I saw a very nice thread here: Display a ConnectionString dialog
Sadly the Link for the sample code is dead
Either way I need to use the object : DataConnectionDialog
this object is in the Windows.VisualStudio.Data namespace. Where can I Include that it's not there in the add reference window. Where can I download that.
I am using VS community 2013
You can add reference to Microsoft.Data.ConnectionUI.Dialog.dll which can be found under
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Microsoft.Data.ConnectionUI.Dialog.dll
Microsoft.Data.ConnectionUI.DataConnectionDialog dlg = new Microsoft.Data.ConnectionUI.DataConnectionDialog();
Microsoft.Data.ConnectionUI.DataSource.AddStandardDataSources(dlg);
if (Microsoft.Data.ConnectionUI.DataConnectionDialog.Show(dlg) == DialogResult.OK)
{
}

Programmatically retrieve version of an installed application

I want to programmatically retrieve the version of an installed application (which is currently running), of which I have the name of the running process. If possible, retrieving the install directory would also be appreciated, but that is optional.
I've searched at a lot of places, and some questions looked similar, but they do not give me what I ask for.
To be a bit more specific, right now I want to do this for Visual Studio i.e. I have a WPF app, which is running alongside Visual Studio & given that I know the process name for Visual Studio i.e. "devenv", how can I get the version information of Visual Studio installed on my machine, from the WPF app? This is just an example, don't assume anything particular to Visual Studio. In the general case, we'd have an app running, for which we know the Process name & want its installed version.
Can you please provide the C# code for doing this?
This is gonna be simple. All kind of system related information will be present in Registry. (i.e) If you open regedit, you may find various HKEY. Now, please navigate to the following location.
" HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall "
You can find many folders inside this location, in which the name of the folder will be encrypted. Those folders indicates the installed application in the current machine.
In each folder there will be many key and data pair of values. In that you can find DisplayName and DisplayVersion. So this DisplayVersion gives you the actual version of your application.
So, How to achieve this through code?
RegistryKey rKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
List<string> insApplication = new List<string>();
if (rKey != null && rKey.SubKeyCount > 0)
{
insApplication = rKey.GetSubKeyNames().ToList();
}
int i = 0;
string version = "";
foreach (string appName in insApplication)
{
RegistryKey finalKey = rKey.OpenSubKey(insApplication[i]);
string installedApp = finalKey.GetValue("DisplayName").ToString();
if (installedApp == "Google Chrome")
{
version = finalKey.GetValue("DisplayVersion").ToString();
return;
}
i++;
}
Process.GetProcessesByName("DevEnv")[0].Modules[0].FileVersionInfo
Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
This gets the version of the executing assembly.
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Public DTE As EnvDTE.DTE
Dim version As String
DTE = System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.9.0")
version = DTE.Version
MsgBox("The visual studio version is {0}", version)

The var keyword not showing up in visual studio

I've installed a new instance of visual studio 2010 premium and everything seems to work fine when I load old projects. When I start to write new classes though, the var keyword is not working or showing up in intellisense. This is a new solution and no web project. (so no web.config) Target framework for the project is set to .net 4.0. When I try compiling it by writing
var x = "this";
I get "A get or set accessor expected" error.
Do I need to reinstall? Any ideas what could be wrong here?
You don't have parentheses after your method name so the compiler thinks you're defining a property.
public void Server_Test()
{
var ...
}

Categories