Insert a new GUID to Visual Studio 2013 - guid

How to create GUIDs in Visual Studio 2013? I had an add in that worked well in VS2012 but it does not work in VS2013. I found this Create GUID in VS2012 and this How to convert VS2012 add ins to VS2013 Packages but could not make it work (add ins are not my forte - I simply edit SQL scripts). Is there an easy way to get back this functionality?

If you're using ReSharper (highly recommended), you can create new GUIDs everywhere by typing nguid and pressing Tab.

Actually, uou can just use guidgen.exe which should get installed with VS.
Using menu TOOLS -> External Tools... add:
%Installation Path%\Microsoft Visual Studio 12.0\Common7\Tools\guidgen.exe
e.g.
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\guidgen.exe
Give the title of ‘Create GUID’ and it is there just as it was in VS2010.

The best tool / add-in for this is:
http://visualstudiogallery.msdn.microsoft.com/22795583-5cc9-4681-af8e-6084f3441655

I was also wondering how I should do this. I saw the following example: Inserting a Guid for VS 2012. For VS2013 you have to install the SDK. Once you have done that you will see the template project items for packages and also for addins when you go to add a new project.
Despite the documentation saying that addins were deprecated in VS2013 they do appear to work (I am using VS2013 Ulitmate v 12.0.21005.1 REL). You can follow the instructions in the previous article.
I also created a package which was relatively straight forward too. Using How to: Convert an Addin to a VS Package I was able to create the package.
As in the article I added the following using statements:
using EnvDTE;
using EnvDTE80;
I then changed the MenuItemCallback method to the following:
private void MenuItemCallback(object sender, EventArgs e)
{
DTE2 dte = (DTE2)GetService(typeof(DTE));
if (dte.ActiveDocument != null)
{
TextSelection objSel = (EnvDTE.TextSelection)(dte.ActiveDocument.Selection);
objSel.Insert(Guid.NewGuid().ToString());
}
}
After building the project I went to the bin\Debug folder and started the vsix file (GuidPackage.vsix in my case). This installed the package for use in the IDE.
I now have a menu item to insert guids into my code and am able to create a shortcut key stroke for it in the usual way.

Just use PowerShell from VS Package Manage Console:
Switch to Package Manager Console (or you can open PowerShell cmd).
Execute [guid]::NewGuid().
Result:
Guid
----
61dabfd8-9151-46f5-8d92-72306044d844

I prefer to use this solution:
_TUCHAR *guidStr = 0x00;
GUID *pguid = 0x00;
pguid = new GUID;
CoCreateGuid(pguid);
// Convert the GUID to a string UuidToString(pguid, &guidStr);
delete pguid;

One other tool that I came by was this extension. Works pretty good
"Insert new GUID" (Shift+Alt+G): Inserts a new GUID at the current position.
"Insert last GUID" (Ctrl+Shift+Alt+G): Re-inserts the last new GUID at the current position.

Related

Exception after join package Microsoft.Extensions.Logging to the template web-api project

After join to the template project of the web application package Microsoft.Extensions.Logging older than version 6.0.0-preview6. * Or new 6.0.0-rc. *, It ends with an exception
MissingMethodException:
Method not found: 'System.Action`4 <Microsoft.Extensions.Logging.ILogger, !! 0, !! 1,
System.Exception> Microsoft.Extensions.Logging.LoggerMessage.Define (
Microsoft.Extensions.Logging.LogLevel ,
Microsoft.Extensions.Logging.EventId,
System.String,
Boolean
) '.
crashes somewhere inside IEndpointRouteBuilder.MapControllers call
Has anyone encountered such a problem before? How to solve it (of course, except for downgrading to the old version)?
Sometimes in Visual Studio, it will ignore the preview version, you can try to check it.
Go Tools -> Options, then select Preview Features as per the screenshot below. Make sure to tick the “Use previews of the .NET Core SDK”.
Without this, Visual Studio will use the latest version of the .NET SDK installed, that is not a preview version.
If the above method does not work, can you show your csproj file?

Asp.net core razor view is not formatted

The razor view formatting is so bad
even when I tried ctrl k + ctrl d
the page is so missed up
any help, please!
#if (item.Details.Length > 10)
{
#item.Details.ToString().Substring(0, 10) }
else
{
#item.Details}
You can enable the new Razor editor first, and then restart VS.
New experimental Razor editor for Visual Studio
Then you can choose Edit->Advanced->Format Document.
✎[Edit]
You can try the following methods:
Check whether three-party plug-ins are installed.
If there are three-party plug-ins installed, temporarily disable them, and then test it.
You can try reset VS settings.
https://learn.microsoft.com/en-us/visualstudio/ide/environment-settings?view=vs-2019#reset-settings
Change the fourth step to select the General option.
Repair VS (repair in VS Installer)
Create a new project and check if the same problem occurs.
Clean up the program /project/VS cache, then restart VS and try again.
The project is cached in the solution/project folder,you need to delete the bin, obj and .vs files.
VS is cached in this path: C:\Users[user name]\AppData\Local\Microsoft\VisualStudio\16.0_XXXXXXXXX, delete all ComponentModelCache folder.
Give feedback to the VS product group from VS-> Help-> Send Feedback-> Report a Problem...

Unable to open SQLite database file from local data store of UWP app

I'm using this section of this official MSDN tutorial: Use a SQLite database in a UWP app but I'm getting the following error:
REMARK: There are many online posts related (or similar) to this issue but none seems to have a solution. Most of these posts are a few years old so I thought this issue would have been resolved by now. Moreover, the above mentioned tutorial is using .NET Standard Class library project, as well. And the online posts regarding the issue do not have .NET Standard involved. So, I was wondering if the issue is caused by the use of .NET Standard library. Regardless, a solution will be greatly appreciated.
SQLite Error 14: 'unable to open database file'
Error occurs at line db.Open() of this code:
public static void InitializeDatabase()
{
using (SqliteConnection db =
new SqliteConnection("Filename=sqliteSample.db"))
{
db.Open();
String tableCommand = "CREATE TABLE IF NOT " +
"EXISTS MyTable (Primary_Key INTEGER PRIMARY KEY, " +
"Text_Entry NVARCHAR(2048) NULL)";
SqliteCommand createTable = new SqliteCommand(tableCommand, db);
createTable.ExecuteReader();
}
}
NOTES:
The line just below the above code reads: This code creates the SQLite database and stores it in the application's local data store. That means the app should have access to that local data store.
I'm using latest version 16.3.5 of VS2019 on Windows 10. The target version on the project is selected as Windows 10 1903 and min version as Windows 10 1903
UPDATE
This similar official 3 years old sample works fine. So, the problem seems to be related to newer versions of .NET Core. But I need to use latest version of .NET Core for other features my app is using that are not available in the older versions.
I also tried this similar old tutorial, but it did not on new version of .NET Core work either - giving exact same error.
The old problem reported in 2016 here to Microsoft seems to have resurfaced again with the new version of .NET Core.
This is a misunderstanding, SqliteConnection db = new SqliteConnection("Filename=sqliteSample.db") can not create a Sqlite file, but access the existing Sqlite database file through the path.
So you need to create a valid sqliteSample.db file and place it in the root directory of the UWP project. Select the content in the Properties -> Build operation to ensure it will be loaded into the application directory.
Update
Please create the sqliteSample.db file in LocalFolder first.
await ApplicationData.Current.LocalFolder.CreateFileAsync("sqliteSample.db", CreationCollisionOption.OpenIfExists);
Then use the path to access the database file
string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, "sqliteSample.db");
using (SqliteConnection db =
new SqliteConnection($"Filename={path}"))
{
// ...
}
Best regards.

String substitution in Visual Studio Team Services

I am setting up a build in Visual Studio Team Services (formerly Visual Studio Online) for my NopCommerce application. The database connection string is defined in a file called Settings.txt and I would like the value to be updated by my build using a build variable.
I have tried using the $(varName) placeholder as suggested here , but it didn't do anything. Any suggestions? Thanks.
You can't use the variable placeholder directly in the file and there's currently no task available OOTB which does replace values inside of files. You'll need to pass it to a Script (PowerShell, Batch, etc) which replaces the value in the file.
You can use the tokenizer task to achieve this. I don't think that it is available in VSTS by default but you can upload it. You can find the instructions to upload and use in Readme.MD
More details at these two links
http://blogs.ripple-rock.com/rorystreet/2015/11/25/UsingVSTSReleaseWithTokenisationToDeployWebsites.aspx
https://github.com/TotalALM/VSO-Tasks/tree/master/VSO%20Tasks/Tokenization

Exception when using SQLite in WinRT app

I'm building a Windows 8 app, and now I want to use SQLite for this app. I installed SQLite for Windows Runtime through the Visual Studio 2013 extension manager, and I added sqlite-net to my project through NuGet.
I'm trying to create a database in my app.xaml.cs OnLaunched, but I get this exception when I run the project:
Unable to load DLL 'sqlite3': The specified module could not be found.
(Exception from HRESULT: 0x8007007E)
This is very strange because there is no error during compiling. Anyway, I think it tries to tell me that I need to reference an additional DLL: sqlite3.dll, but that doesn't work. I have 6 different DLLs on my file system: both debug and release versions of ARM, x64 and x86. I tried adding the x86 release version to my project but that results in this exception:
A reference to 'C:\Users\Leon\Documents\Visual Studio
2013\Projects\Googalytics\packages\SQLite\x86\sqlite3.dll' could not
be added. Please make sure that the file is accessible, and that it is
a valid assembly or COM component.
It's very sad that the documentation for sqlite-net sucks, it's very outdated (examples don't even work anymore), it's very incomplete and there is no mention of manually adding a DLL either. So I have 2 questions:
How do I fix this particular issue?
Where do I find up to date documentation for sqlite-net?
Edit: the code I use to create the DB is:
private void InitializeDatabase()
{
var db = new SQLiteConnection("Googalytics");
db.CreateTable<Account>();
db.CreateTable<WebProperty>();
db.CreateTable<Profile>();
}
I call that method from here:
InitializeDatabase();
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
if (!rootFrame.Navigate(typeof(MainPage), args.Arguments))
{
throw new Exception("Failed to create initial page");
}
}
// Ensure the current window is active
Window.Current.Activate();
edit2: some more info about my setup:
Visual Studio 2013 RC
Windows 8.1 RTM
SQLite for Windows Runtime 3.8.0.2
sqlite-net 1.0.7
Your project has its build mode currently set to Any CPU, what is the default. Because the SqLite assembly is not build as AnyCPU you need to set your build mode to X86 and add the X86 SqLite reference.
When deploying your app you also need to create 3 packages instead of 1 AnyCPU package.
Because your project is AnyCPU you get the error message when trying to add the x86, x86 is not valid for AnyCPU.
UPDATE
I tried to replicate your problem. I installed the SQLite for Windows Runtime for Visual Studio Ultimate 2012, after that I created a Windows Store Project, then added the SqLite reference after that I added sqlite-net and last I added your code for DB creation.
I modified the code a little bit (path & tables). But my code gives no error at all.
I did not need to reference the SqLite assemblies myself. Because by installing the extension into Visual Studio you get the reference in your extension list (still need to select it, just not add the dlls):
But still like I said in my first answer, you need to set your build mode to something else than 'Any CPU'
My example is on my skydrive (when testing set configuration to x86).
UPDATE 2
Db path:
var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
var db = new SQLite.SQLiteConnection(dbPath);

Resources