VSIX - Minor visual studio version - visual-studio-extensions

Does somebody know if/how it is possible to obtain the minor Visual Studio version that is currently running, from within a VSIX extension?
I've already found the following property, but we would like to have the more detailed version number (more parts). https://learn.microsoft.com/en-us/dotnet/api/envdte._dte.version?view=visualstudiosdk-2017

The following code shows "16.0.29306.81 D16.2" in my VS 2019:
var shell = (package as System.IServiceProvider).GetService(typeof(Microsoft.VisualStudio.Shell.Interop.SVsShell)) as Microsoft.VisualStudio.Shell.Interop.IVsShell;
object ver = null;
shell.GetProperty((int)Microsoft.VisualStudio.Shell.Interop.__VSSPROPID5.VSSPROPID_ReleaseVersion, out ver);
System.Windows.MessageBox.Show(ver.ToString());

Assuming you may want the level like X.Y.Z instead of X.0 or X.Y. (e.g: VS2017-15.9.13=>15.9=>15.0).
Sergey's great answer can help you resolve the issue if the format X.Y is enough for you. But if you want to get the full details like VS version+version number, you can consider using registry key.
For VS2015 and earlier versions you can see this vsx document and this similar issue, you can try to use RegistryKey to access the info you want from HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\DevDiv\vs\Servicing\<version>.
But since the installation experience of VS2017 has changed for the vs installer.exe. We can't access the version details about VS2017 and VS2019 under that registry key any more.
For VS2017 and VS2019, I find we can access the related info at HKEY_CURRENT_USER\Software\Microsoft\VSCommon\15.0 or 16.0\SQM\PIDs\.
If in the machine only has one edition of VS2017 and VS2019, you can use code like this to get details:
DTE dte = Package.GetGlobalService(typeof(DTE)) as DTE;
string version = dte.Version;
string editon = dte.Edition;
RegistryKey key = Registry.CurrentUser;
RegistryKey pidsKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\", true);
string[] instances = new string[10];
instances = pidsKey.GetSubKeyNames();
RegistryKey instanceKey = key.OpenSubKey("Software\\Microsoft\\VSCommon\\" + version + "\\SQM\\PIDs\\" + instances[0], true);
//read the details about VSManifestID
string versionInfo = instanceKey.GetValue("VSManifestID").ToString();
The versionInfo's format see here: VisualStudio/15.9.13+28307.xxx (Apart from VSManifestID, you can also use VSChanelID...)
But this won't work if you have more than one edition of same VS version in PC.(VS20xx community and enterprise in same machine). In this situation you have to add much more judgement logic with the help of dte.Version and dte.Edition.

The easiest way to find the minor part of VS is to get version information from the file "devenv.exe":
var devenvInfo = FileVersionInfo.GetVersionInfo(dte.FullName);
return new Version(devenvInfo.FileMajorPart, devenvInfo.FileMinorPart);

Related

VSIX - Get RootSuffix in Visual STudio extension

To debug Visual Studio extensions you can start an experimental instance with a certain "RootSuffix". See https://learn.microsoft.com/en-us/visualstudio/extensibility/the-experimental-instance?view=vs-2022.
Is there a way to know the provided rootsuffix in the code of your extension?
I.e. "Exp" if the instance was started with "devenv.exe /RootSuffix Exp"
The DTE object has a CommandLineArguments property which contains the information you need.
Can be retrieved with following code:
IVsAppCommandLine cmdline = (IVsAppCommandLine)GetService(typeof(SVsAppCommandLine));
cmdline.GetOption("rootSuffix", out var present, out var value)

Looking for Nuget package to install Firebase into Xamarin project in Visual Studio 2019 [duplicate]

I been trying to add google analytics to my xamarin forms apps , but everything I see contains a lot of code, is there any easy way to get this working.It cant be this hard.
I followed this https://github.com/KSemenenko/GoogleAnalyticsForXamarinForms , but when I added the init part it cant find the namespace. the nuget is already installed.
what other steps should I follow?
To use ksemenenko.GoogleAnalytics, install ksemenenko.GoogleAnalytics package, and add the namespace using Plugin.GoogleAnalytics;:
then you can use the api in your porject:
GoogleAnalytics.Current.Config.TrackingId = "UA-11111111-1";
GoogleAnalytics.Current.Config.AppId = "AppID";
GoogleAnalytics.Current.Config.AppName = "TEST";
GoogleAnalytics.Current.Config.AppVersion = "1.0.0.0";
//GoogleAnalytics.Current.Config.Debug = true;
//For tracking install and starts app, you can change default event properties:
//GoogleAnalytics.Current.Config.ServiceCategoryName = "App";
//GoogleAnalytics.Current.Config.InstallMessage = "Install";
//GoogleAnalytics.Current.Config.StartMessage = "Start";
//GoogleAnalytics.Current.Config.AppInstallerId = "someID"; // for custom installer id
GoogleAnalytics.Current.InitTracker();
//Track view
GoogleAnalytics.Current.Tracker.SendView("MainPage");

I cannot create SQLiteConnection in PCL version of Sqlite.net on WP8

I'm using a PCL version of Sqlite.net from https://github.com/oysteinkrog/SQLite.Net-PCL
This code below doesn't work for some reasons on WP8:
var sqliteFilename = Path.Combine(ApplicationData.Current.LocalFolder.Path, "MyDB.db3");
var db = new SQLiteConnection(new SQLitePlatformWP8CSharp(), sqliteFilename);
And I am receiving this error:
An exception of type 'SQLite.Net.SQLiteException' occurred in SQLite.Net.DLL but was not handled in user code
Additional information: Could not open database file: C:\Data\Users\DefApps\AppData\{149B7F85-2C71-4BEF-984F-903BA7DB80DA}\Local\MyDB.db3 (CannotOpen)
What I am doing wrong?
Thank you!!!
#Sergey-Chesalin thank you for your answers. I checked and found that it should create DB when it's not available. After my research I found why it doesn't work as it should.
For some reasons they add additional symbol to the connection string, see Line 121 in SQLiteConnection.cs and Line 196 in SQLiteConnection.cs. Maybe it works as expected in iOS/Android/WinRT versions of ISQLiteApi implementations, but it doesn't work as it should for Windows Phone.
So in order to fix it I have changed this line:
string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length);
To this:
string dbFileName = Encoding.UTF8.GetString(filename, 0, filename.Length - 1);
in the SQLite.Net-PCL/blob/master/src/SQLite.Net.Platform.WindowsPhone8.CSharpSqlite/SQLiteApiWP8.cs line 12
Have you marked your database file file as content in project?
And you can explore deployed project with ISETool or something with GUI like this to check for file existence by this path.

Websphere & Tivoli: NPE while trying to create PDAuthorizationContext

I am getting the following error when I try to start my Application...
[java.lang.IllegalStateException: java.lang.NullPointerException^M
at com.tivoli.pd.jutil.kb$1.run(kb$1.java:41)^M
at java.security.AccessController.doPrivileged(AccessController.java:229
)^M
at com.tivoli.pd.jutil.kb.c(kb.java:141)^M
at com.tivoli.pd.jutil.kb.(kb.java:56)^M
at com.tivoli.pd.jutil.PDContext.(PDContext.java:76)^M
at com.tivoli.pd.jazn.PDAuthorizationContext.(PDAuthorizationConte
xt.java:66)^M
I double checked the config file was accessible and I could read it. The code I am using looks as follows...
aC = new PDAuthorizationContext(cFile);
Is there a way to get more information on what is causing the NPE?
More information!!!
After debuging a bit, it appears the issue comes from this code (they use progaurd so it is a little hard to be 100% confident)...
Certificate[] arrayOfCertificate1 = ((KeyStore)???).getCertificateChain("DefaultID");
//Throws Null pointer (presumably because array is null)
Certificate localCertificate1 = arrayOfCertificate1[0];
EVEN MORE INFO
This appears to be some kind of dependency conflict (guess), because if I just create a sample App using PDAuthorizationContext it works fine.
Problem was related to the PD.jar version that I was using. Although I thought I was using one version I was using another. This was because on version was registered in my WebSphere library (under build path in eclipse). Once the proper library was introduced everything worked.

ASP.NET: Errors in autogenerated .Designer.cs file for Model

I'm new to ASP.NET and having a problem with a tutorial.
I've created a new MVC4 Project in VS2012 Express for Web.
And I've added a SQL Database with 1 Table "Persons" and filled it with some random testdata:
Id int (primary key, is identity=true)
name varchar(50)
birthdate date
adam 01.01.2001
berta 02.02.2002
As a Model I've used ADO.NET Entity Data Model, named it "PersonsModel.edmx"
and used the Personsdatabase for it.
To see the PersonsModel.Designer.cs file, I activated "Codegeneration Status" to "Standard". Refreshed and clicked on the PersonsModel.Designer.cs file.
But in this file I've errors... So I wanted to use something like this in my controller:
HomeController.cs:
PersonsEntities1 db = new PersonsEntities();
db.person...
but it doesn't work, and I think(?) it's because of the errors in the .Designer.cs file.
PersonsModel.Designer.cs: e.g.:
public PersonsEntities1() : base("name=PersonsEntities1", "PersonsEntities1")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
errors in the base: ... line
and in ContextOptions.
Unfortunately I've no english VS, but it says something like:
The best accordance für the overloaded System.Data.Entity.DbContext(string, System.Data.Entity.Infrastructure.DbCompiledModel)-Method has some invalid arguments
And no definition found for "ContextOptions", there is no method "ContextOptions" which accepts "MvcApplication7.Models.PersonsEntities1" as a first argument.
I'm a bit confused, because I did it like in the tutorial explained.
I think this code is in error:
base("name=PersonsEntities1", "PersonsEntities1")
There is no constructor that takes two strings. Your second argument is supposed to be of type DbCompiledModel. (See here.)
Now, I don't know why your designer would produce code that can't compile, so I'm wondering whether you have the wrong version of Entity Framework installed.
Apparently the problem was VS2012. It all works with VS2010.
I've downloaded the installer again from asp.net/mvc and added Visual Web Developer 2010 Express. After installation of VS2010 and all dependencies I tried the tutorial again and all works fine now. No wrong code in the .Designer.cs file :).
Thanks a lot Ann L. for your support. Your hint (wrong version of Entity Framework installed) prompt me to try another VS version.
In addition I've to say: I also tried VS2012 Ultimate (complete DVD version) but it didn't help.

Resources