How can i add local dll at the asp.net 5 project - c#

I am trying to make an ASP.NET 5 site use visual studio 2015 preview, and i want to add dll at local file system to the ASP.NET 5 project. But i can't find this option, Is it no longer possible to add local dll? If yes, why?

You cannot add direct reference anymore, you would have to create your own nuget package containing it.
See: http://forums.asp.net/t/2002302.aspx?Adding+a+non+nuget+reference+to+a+vNext+project
As for the why, it is really easier to manage dependencies with nuget, download your sources anywhere, and with a single command (kpm restore) all nuget packages necessary will be downloaded.

If you have project code than you can add Foo.csproj to Bar.xproj as reference but not directly, see instructions below. It can be done without uploading packages in Beta8 but it is not simple as it should be. If you only have Foo.dll there is one hint here: Bin syntax (wrapping a dll)
Go too Foo.csproj folder, type: dnv wrap Foo.csproj.
You should now have some files generated, for me it was Foo/wrap/Foo/project.json. Go to your solution in Visual Studio, Add -> Existing project -> project.json.
Now you have some more files, including Foo.xproj which is available in Visual Studio solution, but it does not build.
Open cmd in Foo dir and execute dnv restore.
After 4) completes with no error and Foo.xproj can be built you can now go to Bar.xproj and add Foo.xproj as reference.
Open cmd in Bar directory and execute dnv restore.
You can now build Bar.xproj
I really hope that this will be easier in final version.

Related

How to add project dependencies in a MSBuild solution programmatically with C#

Hello I ran into a XY problem using Visual Studio 2017 and dotnet 6.0.100
My original problem is: "How to add project dependencies in a MSBuild solution programmatically with C#"
This is needed to force a modular application to compile unreferenced projects in a .sln during the build process to also compile all other projects in the solution.
This .sln file is built programmatically and should also do this step automatically during creation of the .sln to reduce possible problems for the user working with this .sln.
The .csproj of the projects however should not be touched since they are part of a git submodule, that should not include these changes to the .csproj but only the changes to the .csproj made by the user.
Solution
There is a 10 year old solution described here and here using the DTE Interface.
Derived problem: I failed to include the correct references for the EnvDTE.DTE or EnvDTE80.DTE2 objects to be available in code.
I tried adding the Microsoft.VisualStudio.Setup.Configuration.Interop NuGet package and searched in the references for EnvDTE or Microsoft.VisualStudio.Shell as seen e.g. in the example here without luck.
Original problem
Manually the project dependencies can be added as described here
I tried adding the project dependencies via the dotnet sln command but didn't find a corresponding command to add the dependencies.
dotnet sln -h only points to add, list and remove. The add command didn't show an option for dependencies.
Since I already use dotnet commands to create the solution and add projects this would be a good solution for me if there is a way.
The other thing I tried was using Microsoft.Build.Construction:
SolutionFile solutionFile = SolutionFile.Parse(PROJECT_SOLUTION_FILE.FullName);
var projectInSolution = solutionFile.ProjectsInOrder;
which does enable me to read the projects in the sln but seemingly not to manipulate it since its all readonly.
Summary
I need a way to tell the solution that all projects have to be compiled on run/compilation of the designated one.
To accomplish this I either need a way to add project dependencies to the .sln file via
dotnet shell commands
something like Microsoft.Build.Construction
or a good source explaining to me how I can get the EnvDTE code running in my MS Visual Studio 2017
or there is some awesome way to do this that I didn't stumble across yet
I really appreciate any help to solving my problem.
Edit:
To clarify project dependencies are different from project references in .csproj files!
The project dependencies I refer to are this section in the .sln:
Project("{GUID}") = "PROJECTNAME", "CSPROJECT_LOCATION", "{GUID}"
ProjectSection(ProjectDependencies) = postProject
{GUID} = {GUID}
{GUID} = {GUID}
...
EndProjectSection
EndProject
I found the solution to my Y problem, adding the dependencies using EnvDTE as described in the answer.
The references for EnvDTE and Microsoft.VisualStudio.Setup.Configuration.Interop did not show up because I was using a SDK-Style project to test them, since we do use them by default currently.
Installing the Microsoft.VisualStudio.Setup.Configuration.Interop NuGet did not remedy this either!
According to this question SDK-Style projects do not support working with the DTE Interface yet.
That is the reason, why I was unable to find the references described in this example.
The example also mentions creating a .NET Framework Console App, which I did not see as a requirement at the time.
Summary:
To work with the DTE Interface in 2021 better use the old project format and avoid the SDK-Style project format!

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.

Reference shared project in multiple solutions

I have a solution AddLog which has only one project AddLogClient of type shared project. I created it by right clicking on solution name->Add->Shared Project.
I want to use this shared project in other solutions. When I go to another solution MyApplication and want to add a reference to AddLogClient, I can't see it in the list of shared projects, because it is not located in the same solution. When I try to browse for it, it expects a file in .exe, .dll, .tlb, .olb, .olx or .winmd format. Adding .dll file (from bin folder from AddLogClient) would not be acceptable because every developer has different repository checkout location and we can't use relative paths.
How can I reference shared project from other solutions? Both solutions are under SVN.
The standard way of doing so, as #Sokopa suggested is through NuGet. For dev purposes, if you do not want to publish packages to Nuget servers, you can check the Generate Nuget Package on Build option and upon build it will create a nuget package in your build folder.
check this guide from microsoft docs

Add Dynamics GP namespaces Visual Studio project

I need to add the following namespaces
• Microsoft.Dynamics.Common
• Microsoft.Dynamics.Common.Types
• Microsoft.Dynamics.GP.BusinessLogic
• Microsoft.Dynamics.Common
• Microsoft.Dynamics.GP
to my project in Visual Studio,
Kindly suggest how I can do so.
First you need to add references to the libraries to your project. Right click the project name and select "Add Reference" or if the project shows a references folder right click that and choose to add. If the library doesn't show in the list then browse to where ever it is located and select it.
Then at the top of the file add a using command. For example:
using Microsoft.Dynamics.Common;
Please feel free to post additional questions.
Either Download and install the SDK on your machine, It will include the dlls needed to integrate with dynamics or copy the dlls from where ever you have them. (make sure you get the correct version for GP). From there you should create a folder in your project to hold the files in one place and copy them there. Once you have the library files you add references to the files by going to the browse sections of the reference manager and then browsing to the where you copied the files. (Quick note. make sure that you set copy local to true so that it will include the files locally when running and not look for them in the GAC). Once referenced you should be able to access the namespaces and include them with using keyword as needed.
If in case you are not getting the required dlls even after installing SDK, then add required Nugets online in visual studio(and later). After that you can start using the keyword "using" in your VS project.

How to appropriately treat the assembly on the package folder when check in to the TeamFoundationServer at VisualStudio.com?

I was creating ASP.NET MVC 5 web app and put it in the Team Foundation Server source code control (visualstudio.com). There is a folder named "packages" that contains all assembly I've got thru nugget. After a while, I need to create another app, and I use TFS to get latest version of my code from TFS. But all the references to the third parties assemblies that point to the folder "packages" seems to have some problem. The icons has yellow triangle with exclamation point for each assembly. How do I fix this problem?
That's because NuGet just creates the folder with referenced packages but it doesn't add it to your source control. Why don't you just add the folder NuGet created to your solution and that way it will become a part of your project in TFS?
That way your TFS server will have all the required packages and will be able to copy the packages to your new solution or if you try to open the solution on another computer.

Categories