No package autocomplete in asp.net core .csproj? - c#

Previously, we used the project.json to setup our projects dependencies. The Asp.net Core team moved away from that and went back to using .csproj. However, when trying to type in the name of a package, it no longer auto-completes like it used to.
For instance, typing in the following line would show intellisense when I typed the . after Microsoft, providing me with the packages within that namespace.
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" PrivateAssets="All" />
How do I get this functionality back?

It's still there in a Editor Extension called "Project File Tools" which is a Microsoft Extension and I am pretty certain this should be installed by default, but on VS 15.3 Preview it didn't seem to be working (was installed, but I didn't had any other extensions there). Somewhere in between disabling/restarting/enabling it and/or installing the Web Essentials it started working again.
As for Ctrl+. doing a reverse package search, it's there too but disabled by default:
Go to Tools > Options > Text Editor > C# > Advanced (or hit Ctrl+Q and type "C# Adv" + Enter) and check "Suggest usings for types in NuGet packages".
If you already have a highlighted error before setting the changes you got to remove the piece of code and add it again before it gets recognized (read: it only applies for red-squiggles that happen after the change).

This will probably depend on which IDE you are using.
If you're using Visual Studio then you'd right click on dependencies or csproj then click "Manage Nuget Packages".
This will open a view where you can search for packages and install them.
If you're using Visual Studio Code, there are couple of plugins that'll help you search and add packages you're looking for.
https://marketplace.visualstudio.com/items?itemName=jmrog.vscode-nuget-package-manager
Lets you search package and add specific version.

Related

ANTLR4 runtime problem in visual studio 2019

I'm trying to get antlr working in VS. I’ve not touched VS for a very long time. I've added the AntlrVSIX extension per the Antlr online docs, this created a sample calculator project for me but I can't compile it (I uninstalled and reinstalled AntlrVSIX but it made no difference to the following problem).
VS complains “The type or namespace name 'Antlr4' could not be found (are you missing a using directive or an assembly reference?)” and points to the line “using Antlr4.Runtime.Misc;” (and lots more similar).
If I look in menu Tools:NuGet Package Manager:Manage NuGetPackages for Solution… it clearly shows Antlr4.Runtime.Standard present and installed (showing version 4.8.0).
I guess I have to add a reference to this dll to my project so I I right click on References:Add Reference... in Solutions Explorer but I can’t find it in any list, however I search.
There is a Browse button which I assume I could use to link to the DLL directly, so I’ve searched the disk, found the dll and linked to that. This now works in that all those errors go away, but this can’t possibly be the right way.
So how do you add a reference to it properly, using References:Add Reference...? VS knows it’s there, it displays it, but doesn’t let it be referenced like that because it won’t show it within VS via References:Add Reference...
On your specific question, yes, you don't want to add a reference to the dll. Instead, you need to add a "<PackageReference>" in the csproj for these dependencies. All this lives in Nuget.org. So, in VS2019, right click on a project in the Solution Manager, then look for "Manage Nuget packages" to add Antlr4BuildTasks and Antlr4.Runtime.Standard.
Note, I've been updating the Antlrvsix extension, but haven't made a release for 2 months, longer than my usual schedule, because the next version has a huge number of changes. I will be cutting version 8 in a week. The template in VS2019 was removed because it is old and out of date. It uses an ancient version of the Antlr4BuildTasks. Instead, use the Antlr4BuildTasks.Templates v8.1 to create a C# project from scratch. Please follow the directions here. You don't need to download the Antlr tool kit, Java, or set any environmental variables. You also don't even need to use VS2019. You only need Net Core 3.1 and to install Antlr4BuildTasks.Templates. Then, type "mkdir foo; cd foo; dotnet new antlr; dotnet restore; dotnet build; dotnet run" at a command-line shell to create a C# application with Antlr4. Once you create the application, you can modify that to what you need. If you start from a Net Standard or Net Core project that doesn't have Antlr yet, you will need to add in the project reference for Antlr4.Runtime.Standard 4.8 and Antlr4BuildTasks 8.1, add in all grammars, and driver to set up and call the parser--harder to do, but it can be done through VS, or you can edit the CSPROJ file more easily and faster. The Antlr4BuildTasks looks at your CSPROJ file and will see that Antlr4.Runtime.Standard 4.8 is referenced, then will use the correct version of the Antlr JAR file to generate the parser and lexer. Any questions, let me know.
I suggest you using Antlr4.CodeGenerator NuGet package, it's gonna generated all necessary files (visitors, listeners) to work with your grammar in antlr. Check out my article for the details, there is a link to Github repo with the solution that works in VS 2019.

Nuget package for System.Web.Hosting

In a legacy project I am working on, there is a using directive:
using System.Web.Hosting
I supposed, that the nuget package name should be System.Web and tried to install it via Nuget.
But there's no such package.
Question: where can I get this package and how?
System.Web is not a nuget-package, it's a framework reference and System.Web.Hosting is one of the namespaces located in System.Web
Depending on your project-type, whether it's the old or new format, you have to do the following
For old format:
Locate the project and collapse it
Right click on "References" and press on "Add reference"
In the window that pops choose the menu on the left named "Assemblies" and then search for "System.Web"
For new format:
Right click on the project and press on "Edit"
Find an existing <ItemGroup> or add a new one
Add this line <Reference Include="System.Web" />
I did not know that System.Web is not available for .netstandard projects. And my project is a .netstandard project (migrating from .net framework).
This is the reason why the System.Web package is not available. I think it would be far more better, if unavailable packages would be displayed, but with message, that they are not availble for a particular reason.
Otherwise users spend much time to finding out the reason of such issue.

Some projects' dependencies contain unexplained code analyzers

I have a couple of projects where under Dependencies there are one or two branches of code analyzers like this:
I tried the right mouse click on every branch as explaind here but there is no option to configure them and I also searched for *.ruleset files insinde the solution, I also check the packages as shown in the docs but there is nothing like that anywhere.
There is also nothing suspicious in the .csproj files, just some nuget packages that I've installed but nothing analyzer related.
How do I get rid of them? They give me warnings when I reference such projects in other solutions and nuget restore doesn't fix it either:
I have no idea where they come from. Some projects have them and others don't. However, they seem to somehow be related to ASP.NET Core or MVC packages that are installed in those projects.
There is a bug in Visual Studio and it is supposed to be fixed soon.
When Visual Studio loads all projects for the solution and tries to resolve all dependencies to display in Solution Explorer, some dependencies may fail and display as warnings with the path of the likely file for the dependency.
Workaround:
Right click the project with the warnings, and select Unload Project on the menu. Then right click it again and select Reload Project. Because Visual Studio is less busy with background processes than it was when it was loading everything for the entire solution, it is likely to resolve the dependency. It seems to always work for me.
I've fixed the warnings by deleting the microsoft.codeanalysis.analyzers folder and executing nuget restore. They are still under Dependencies but at least the exclamation marks are gone.
I've also managed to remove the analyzers by adding the <ExcludeAssets>analyzers</ExcludeAssets> directive to each AspNetCore package:
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3">
<ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" >
<ExcludeAssets>analyzers</ExcludeAssets>
</PackageReference>
Now they're finally gone.
Search Gcop in nuget package manager removes the installed packages
prefixed with GCop. this will remove the code analyzer references from
your project

Create a Visual Studio Project Template that pulls NuGet references from online feed

I'm creating a Visual Studio Project Template and bundling it inside of a VS Extension. I need Projects created from the Template to reference ~20 NuGet packages.
Is it possible to have the references resolved from nuget.org rather than having to include all of the references inside the VSIX?
The NuGet documentation on Visual Studio Templates provides instructions on how to add packages inside the VSIX, but it requires the file be stored locally on disk and the .nupkg is bundles inside the vsix:
Add your nupkg files as custom extension content in your source.extension.vsixmanifest file. If you're using the 2.0 schema it should look like this:
<Asset Type="Moq.4.0.10827.nupkg" d:Source="File"
Path="Packages\Moq.4.0.10827.nupkg" d:VsixSubPath="Packages" />
Question already asked
I know a similar question was asked (Creating a Visual Studio Project Template that already includes a Nuget Package Reference?) and answered (not possible), but this was asked in 2011.
5 years later, is it still not possible?
Since there is still no Built-In functionality to Install/Upgrade packages from online Repo, here is a small workaround wich might help:
Prerequisites
First, install the NuGet.VisualStudio nuget package into your project.
You get that from here
When installed, the package will automatically set the Embed Interop Types property of the assembly reference to True. The reason it does so is to make your code resilient against version changes when users update to newer versions of NuGet.
For the same reason, you must NOT use any other types besides the above interfaces in your code. You must NOT reference any other NuGet assemblies either, including NuGet.Core.dll.
After setting up all that stuff, you can do the following in your RunFinished-Method:
var componentModel = (IComponentModel) Package.GetGlobalService(typeof(SComponentModel));
IVsPackageInstallerServices installerServices =
componentModel.GetService<IVsPackageInstallerServices>();
if (!installerServices.IsPackageInstalled(project, "Newtonsoft.Json")) {
var installer = componentModel.GetService<IVsPackageInstaller>();
installer.InstallPackage(
"All",
project,
"Newtonsoft.Json",
(System.Version) null,
false);
}
Note
That example shows based on Newtonsoft.Json how you can install a package.
For sure you can choose the projects targeting the installation. Also you can determine the Version to be installed.
It seems a bit uncomfortable, but unfortunately there is no other way around.
Usings
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using NuGet.VisualStudio;
Let me know if that helps!
Yes, you can create a nuget package and add those other packages as its dependencies. Then when you download that package it will get all its dependencies and add to your project.

Documentation project type missing after NuGet Sandcastle Install

I have installed the most current version of Sandcastle from NuGet (EWSoftware.SHFB version 2015.10.10.0), and the needed Reflection package (EWSoftware.SHFB.NETFramework version 4.6).
I read #Frank-Rem answer to Numid's question How to generate documentation using Sandcastle NuGet package (EWSoftware.SHFB)? and tried to add a new project to my solution. However, when I try to add a Sandcastle Documentation project I do not have the Documentation project type as an option.
I uninstalled the NuGet package and reinstalled it, thinking it may have been a buggy install. But the documentation project type is still not an option, even after shutting Visual Studio down and relaunching it.
I read through the readme.txt file and saw that I will need to add some property tags to the .shfbproj file when it gets generated. Beyond that, I don't see any other steps that I need to perform or packages to install in order to get the project type to show up. I have also gone to the GitHub project page and checked the Issues tab to make sure this isn’t a known issue they are working on.
I am using Visual Studio Ultimate 2013.
Are there additional steps I need to take to get the Sandcastle project type to show up in the Add New Project list?
Thank you for any ideas!
I was able to resolve the issue by running the Sandcastle Help File Builder Guided Installer. This identified missing components and installed them.
I was then able to follow the instructions from #frank-rem on adding the documentation project and documentation source to the new project.
Assuming that you already have a solution with a project, add a new project of type 'Documentation' to your solution.
Right-click Documentation Sources and add a source by selecting the csproj you wish to document.
Then just build.
Additional steps I took to get a finalized help doc: I found that Sandcastle had added several TODO items, which didn't show up in the Visual Studio task list. So I did a search on the solution for TODO and resolved them that way.
After that I followed the instructions on adding the namespace summaries provided by #davy-landman (in a comment to Davy Landman's answer) to clear up some missing flags.
This has actually changed in the latest version (currently 1.9.3.0) to Project Properties > Summaries > NameSpaceSummaries. – Ant Swift Jan 6 '12 at 9:44

Categories