How to add Project Reference in asp.net 5 application - nuget-package

As per my knowledge, Visual Studio 2015 has some update and we can't add DLLs in asp.net 5 application any more, if we need to add then we need to make NuGet package and then install it.
Now my Questions are:-
1) If I have one project with two class libraries then how can i add that class library's reference (DLL) in my asp.net 5 application?
2) If a class library is also in development mode then how to update that DLL in asp.net 5 application if that DLL install via NuGet, because every time for publish on NuGet and get latest take more time.
3) Suppose if we need to add all DLLs using NuGet then what about private DLLs?
4) Is there any way without NuGet package manager to handle this?

Quick answer - you don't need NuGet packages for that and yes, it's possible to refer your own libs.
Two ways:
By adding it into root level "dependecies" object in your project.json. Be aware that this action will add reference into every target framework listed in the "frameworks" section, therefore if you adding reference to the old-type class library it would not work with new DNXCore 5.0
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Library": "1.0.0-*"
By adding it for specific framework version. Which is more flexible as you can use old-type libs for DNX451 and new vNext Class Libraries for DNXCore 5.0
"frameworks": {
"dnx451": {
"dependencies": {
"ClassicLib": "1.0.0-*",
"vNextLib": "1.0.0-*",
}
},
"dnxcore50" : {
"dependencies": {
"vNextLib": "1.0.0-*"
}
}
} ....
All samples I've checked on Visual Studio 2015 RC.

You can add old class library Foo.csproj to Bar.xproj as reference but not directly, see instructions below. It can be done without uploading packages in Beta8.
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 dnu 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 dnu restore.
You can now build Bar.xproj
I really hope that this will be easier in final version.

I have edited my previous answer to point you to the following answer on StackOverflow:
Issue adding reference to class library project in ASP.NET 5 (Core)
I can verify the answer there works if your front-end project, the one from which you need to reference other class libraries, is ASP.NET 5 MVC 6 beta6.

You need to create a project.json for your assembly.
you can use the command :
kpm wrap "c:\path\to.csproj"
This will create a "wrap" folder in the solution root folder. Then you must be able to add reference to your project. If it don't work, try to move the project.json in the project directory.
To use kpm(K Package Manager), you need to have installed the "k" and "dnx" tools and have a active version installed.
If kpm command don't work, folow this:
1) Open PowerShell as admin and type this command to allow the powershel to download and install the package:
Set-ExecutionPolicy RemoteSigned
2) Open a cmd with admin right and enter the folowing command to install the package:
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"
3) In cmd, you can update and set the environement varriables with the foloing command:
dnvm upgrade
then try again the "kpm wrap" command
After that, you will be able to add a reference to your project. But i thing it will not work with core. if you have problem, try use an other dnvm version (like beta2 or "2 1.0.0-beta5") with the command dnvm install like this:
dnvm install 1.0.0-beta4-11566

Related

Ho to trace dll to some nuget package

I'm working on relatively big solution with many projects in it. Almost each project has dependencies on some nuget packages. In the output folder bit/debug/net6.0 of startup project I have found BouncyCastle.Crypto.dll and I would like to find out where it's comming from.
I have checked all the project files but there is no references to BouncyCastle.Crypto neither any reference in any of .cs files. So it must be a transient dependency.
Question is there easy way to find out nuget package from which this DLL is comming?
Is there is UI for it e.g. in Visual Studio / Resharper or if there is some command for dotnet CLI?
You can use build with --verbosity flag, like this:
dotnet build --verbosity detailed
And then, in output you can grep or search for relevant dll, you'll find something like this:
1:7>Target "_CopyFilesMarkedCopyLocal" in file "/opt/.dotnet/sdk/6.0.403/Microsoft.Common.CurrentVersion.targets" from project "/SOME_PATH/SOME_PATH/SomeProjectName.csproj" (target "CopyFilesToOutputDirectory" depends on it):
Task "Copy"
Copying file from "/SOME_PATH/.nuget/packages/bouncycastle/1.8.9/lib/BouncyCastle.Crypto.dll" to "/SOME_PATH/SOME_PATH/bin/Debug/net6.0/BouncyCastle.Crypto.dll".
Done executing task "Copy".
from project line, will point you to the actual project. Copying file from and to will point to the actual dll.

IIS web application "Build (web): Object reference not set to an instance of an object."

I inherited an old web application built using IIS, and I'm trying to figure out how to build it. I'm running into this Build (web): Object reference not set to an instance of an object. error during build time. Aren't null object references supposed to be runtime errors, not compile errors? Can anyone explain to me what's happening here and how to fix it?
Have you downloaded the packages your projects reference? And do the assemblies in your bin folder match up with your web.config (check version numbers too)?
Edit: If the packages in the bin folder don't match, you can redownload them with NUGET -
note which packages are out of sync - grab their id values from the package nodes in the web.config
Inside your VS solution, check each project's references to see where the missing packages are referenced
Inside your VS solution, go to: Tools > NuGet Package Manager > Package Manager Console
for each missing package run the following command in the Package Manager Console:
Update-Package -Id <package_name> –reinstall
where <package_name> == the id value you captured from the web.config at step 1.

How to use npm package (for example, DOMPurify) in an asp.net core application

Can anyone point me to instructions on how to use an npm package in an asp.net core application using Visual Studio 2019? Specifically, I am using the DOMPurify npm package (https://www.npmjs.com/package/dompurify)
I am new to npm and feeling my way. I have npm installed on my machine. I added a package.json to the project, and in there I added this bit of code:
"devDependencies": {
"dompurify": "2.2.6"
}
When I hover over this with my cursor I see the DOMPurifiy intellisense information, and a folder named "npm" was added to my Dependencies node, and in there I see "dompurify (2.2.6)", so something happened, but no files get downloaded. I was expecting something like adding a Nuget package, where the files get downloaded, but that does not occur.
I simply downloaded the javascript file I need from the github site and added that to my project, and it works fine. What is the purpose of the package.json and the "npm" dependencies node? Is there any way to manage these packages in Visual Studio, similar to how Nuget works?

Call executable inside Nuget package cache from launchSettings.json

I created a small executable that is used to run and debug specific libraries from other solutions. The executable is given the path to a library as a command line argument which the executable loads at runtime.
I want to put my executable in a Nuget package, and have consuming libraries just add the Nuget package to be able to run and debug, using a launchSettings.json.
Because the executable is in the tools/ directory of the Nuget package, its path is put into the PATH environment variable by the Package Manger Console. Therefore the launchSettings can simply just call the executable.
I create my Nuget package with nuget.exe pack my.nuspec -Version 1.0.0, with my.nuspec containing:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>DebugHost</id>
<version>$version$</version>
<title>DebugHost</title>
<authors>Some company</authors>
<owners>Some company</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>DebugHost</description>
<summary>DebugHost</summary>
<copyright>2020, Some company</copyright>
</metadata>
<files>
<file src="bin\Debug\netcoreapp3.1\*" target="tools" />
</files>
</package>
From consuming library projects I put in Properties\launchSettings.json containting:
{
"profiles": {
"DebugHost": {
"commandName": "Executable",
"executablePath": "my.exe",
"commandLineArgs": "$(ProjectDir)$(OutDir)$(TargetName)$(TargetExt)"
}
}
}
I have three different questions that are somewhat related, as any might answer another:
This setup only works as long as I keep the Package Manager Console opened. If I try to Debug / Launch the library without first opening the Package Manager Console, the launch fails because it cannot find the executable. Unable to start program 'my.exe'. The system cannot fint the file specified.
Can I for example add a targets file in the Nuget package that will hint its path during build/launch, which in turn I can use as a variable in the launchSettings.json? (If so, how?)
This setup requires that a Properties\launchSettings.json is used in the consuming project. Can I make my Nuget package create that file?
Can the file be an asset in the Nuget that gets copied to the correct place?
Or can I even have an install.ps1 script that creates the json, with the correct absolute path to the executable in it? This would make question 1 answered as well.
The above situation only works with nuget.exe pack and a .nuspec.
Can I instead move stuff into my (new style) .csproj and get this to work with just dotnet.exe pack and the .csproj? (or msbuild.exe -t:pack and the .csproj?) So ultimately I can also just create the package by simply right clicking the project in Visual Studio and selecting Pack from the context menu?

build script don't runs when creating a Node.js and React app in Visual Studio

I following a step by step guide to configure Visual Studio 2019 in order develop a Node.js-React app.
The guide is here:
https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-nodejs-with-react-and-jsx?view=vs-2019
Briefly, the guide tells to configure an npm script (called "build") that should be fired when visual studio compiles, in order to generate app-bundle.js through typescript, using the app.tsx which contains a react component.
This must be done by adding the following code snipped to package.json
"scripts": {
"build": "webpack-cli app.tsx --config webpack-config.js"
}
however it doesn't work, because when i change something in app.tsx and run visual studio debbugger, the web page don't change at all.
If I run the following command using the nuget package console
npm run-script build
then it works fine!
So, is this a VS2019 bug, or is there some trick i miss?
Many Thanks for the help
I had similar problems like yours.
I solved this problem by this undocumented feature of visual studio 2017,2019:
BY manual editing,
You can add the following post-build event to package.json
"-vs-binding": { "AfterBuild": [ "build" ] }
by GUI,
in task runner explorer window,
select "build" task and let popup context menu open using right-mouse-button,
select bindings -> After build (make its preceding check box on)
this will add "-vs-binding" property to your package.json
Either one is okay. This works on vs 2017 and may works on vs 2019 either.
VS2017,2019 nodejs project build process seems
not to actually call my "build" script at all.
we should specify the "build" script as post-build event
for vs default nodejs build action.
It seems weired. I hope Microsoft solve this fault using patches.
task runner explorer capture image

Resources