Is it possible to add a reference to NetCore library from a NetCore app without using the same solution? - .net-core

I have a netstandard1.6 Project "MyLibrary"
I have a netcoreapp1.0 Project "MyApplication"
I have to reference "MyLibrary" from "MyApplication", without having those on the same solution.
Is it possible? How?
It's really confusing how DNX RC1 jumped into what Asp .Net 5 is right now, I can't seem to get going with it, I've read several articles and no documentation answered those questions to me.

With .Net Core, there are two ways to reference dependencies:
Reference another project in the "solution", where the solution is specified by a global.json file.
For example, the relevant part of your project.json could look like this:
"dependencies": {
"MyLibrary": { "target": "project" }
}
Reference a NuGet package from a known package source. Package source can be either web-based (like nuget.org), or it can be a directory. You can configure known package sources either locally or globally using a nuget.config file.
Example project.json excerpt:
"dependencies": {
"MyLibrary": "1.0.0"
}
For you, this means you have two options:
Add the library project to your "solution" by including it in your global.json.
Produce a NuGet package from your library (you can use dotnet pack for that), place it into a package source (probably just a directory) and configure that package source in a nuget.config file.

Related

.net core package restore failed

Package restore
Package restore failed in ASP.NET Core 1.1.
Note: I am targeting following in my project.
"frameworks": {
"net461": { }
},
Recently I upgraded my project from ASP.NET Core 1.0 to 1.1 and it worked fine on my old laptop until I switched the project to fresh new laptop, and installed visual studio 15. Here is the configuration of the VS 15.
I have also installed the required SDK as mentioned on this link
https://jeremylindsayni.wordpress.com/2016/11/20/upgrading-from-net-core-1-0-t0-1-1-with-visual-studio-2015/
Now my project.json file looks likes this.
And global.json looks like this.
{
"projects": [ "." ]
}
But as you can see the packages are not loading as expected. When I run dotnet restore from the package manager console I get something like this.
Any ideas ??
I fixed same issue when i add file
If you see this error with adding some code file for example Controller, View etc.
Than one of reasons is CodeGeneration package failed when you try to add some file.
add nuget package which is
Microsoft.VisualStudio.Web.CodeGeneration.Design

How to run ssis package in asp.net core application?

I have used Microsoft.SqlServer.Dts.Runtime to run package in ASP.NET MVC. However I need to run this in asp.net core. As we cannot add individual dll in asp.net core, I was wondering if anyone has idea if there is nuget package which would help.
Just to elaborate on how I resolved this issue. Below is the answer
To run SSIS package you need below DLLs in the code
Microsoft.SqlServer.ManagedDTS.dll
Microsoft.SqlServer.PipelineHost.dll
Microsoft.SqlServer.DTSRuntimeWrap.dll
Microsoft.SqlServer.DTSPipelineWrap.dll
It is easy to add DLLs in MVC projects, however in asp.net core it needs to be in form of a Nuget package.
So nuget package can be easily created using nuget package explorer. Below is the link
https://docs.nuget.org/create/using-a-gui-to-build-packages
In the nuget package explorer add a lib folder, inside that add a .net folder dnxcore50 and add the above DLLs. Click on tools analyse package and save the nuget
In the visual studio 2015 solution, you can refer local packages.
Tools - Nuget Package Manager - Package Manager Settings - Package source
add the local package path.
After which you will be able to add the nuget package using nuget package manager and select local package as source
If there is error in restoring package, add dnxcore to imports section and add "Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027" to dependencies in project.json
"dependencies": {
"Microsoft.AspNet.Hosting": "1.0.0-rc1-final",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1-rc2-24027",
"SSISPackage": "1.0.0"
}
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8",
"dnxcore"
]
}
}
After which you will be able to use code to run SSIS package similar to MVC projects.
Application app = new Application();
Package package = null;
try
{
package = app.LoadPackage(#"C:\Files\Package.dtsx", null);
Variables vars = package.Variables;
vars["status"].Value = "ACTIVE";
DTSExecResult results = package.Execute();
}
catch
{
return false;
}
finally
{
package.Dispose();
package = null;
}
You can package the assembly into a nuget package, Create a Lib folder inside your solution to hold the nuget package, then, create a nuget.config file to set the package sources to include the Lib folder inside your solution.
The following links contains more details about creating nuget package and hosting it locally:
https://docs.nuget.org/create/creating-and-publishing-a-package
https://docs.nuget.org/create/hosting-your-own-nuget-feeds
https://docs.nuget.org/consume/nuget-config-file
Hope that helps
You may now reference the dlls ( one from each) directly in your .net core project from the below locations to run ssis packages now
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.ManagedDTS
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.PipelineHost
C:\Windows\Microsoft.NET\assembly\GAC_64\Microsoft.SqlServer.DTSRuntimeWrap
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.SqlServer.DTSPipelineWrap
you no longer need to create a nuget package

Could not find System.Runtime 4.1.0.0 when running ASP.NET web application

I've created a Portable Class Library with the following projects.json
{
"supports": {},
"dependencies": {
"Microsoft.CSharp": "4.0.1",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"System.Runtime": "4.1.0"
},
"frameworks": {
"net451": {},
"netstandard1.5": {}
}
}
However, when referencing this from an ASP.NET application (not ASP.NET Core), I get the following runtime exception:
Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
If I reference it from a console application it runs without issues.
Any ideas?
Edit
Found a solution here: https://stackoverflow.com/a/37639003/691045
As mentioned in the update one solution to this problem is to package up the PCL as a nuget package. This however goes contrary to what one is trying to do when one targets .Net Standard with a PCL. Also the package solution becomes cumbersome to debug.
To me it appears as a bug with Net Core Tools Preview when crossing the csproj to xproj boundary. To evidence this if one install the package via nuget:
Install-Package System.Runtime
The System.Runtime looks correct in the project.json as "System.Runtime": "4.1.0". Looking at the references, one will see that the version is listed as System.Runtime (4.0.20). Also the actual bin has absolutely reference to the actual dll.
Simply copying the .Net 4.6.2 dll from the nuget cache into the bin solves the problem. This allows for direct references without packaging up your PCL.
Hopefully when we hit Net Standard 2.0 and the tooling matures a bit more this type of thing will be a thing of the past.
UPDATE: If you use the latest .Net Core release (1.1) and binaries this is fixed. The tool preview is still on 1.0.1 so you have to make sure you install the binaries for 1.1.
I was getting a similar warning from ReSharper while running unit tests:
The solution that worked for me was to run this in the Package Manager console:
Update-Package System.Runtime -Reinstall
What I observed is that before running the above command, the reference in the affected project was to System.Runtime v 4.0.20.0, but post execution, it changed to 4.1.1.0
I was experiencing this issue after upgrade the .NET framework from 4.6.2 to 4.7, after digging around on several forums and the internet for a while and trying a lot, I found a solution and consits in two steps:
I deleted all Dependent Assambly and update all nugets UPDATE-PACKAGE -projectName -reinstall.
After the first step, I checked every missing assambly that throw me an exception in runtime and realize that in some cases the framework has a dll in our local machine that has nothing to do with the nuget then I deleted all local's dll references and install it from the nuget. After cleaning from the missing dll taking them from the Nuget my project run without any issue.
Hope that help you.

Polymer Paper Elements in ASP.NET MVC via Nuget?

With the recent release of Polymer 1.0 I was hoping to use the Paper Elements in a ASP.NET MVC/Microsoft Stack, or at least check them out.
I have used nuget in the Visual Studio package manager to attempt to install polymer:
PM> Install-Package polymer
Installing 'polymer 1.0.0'.
Successfully installed 'polymer 1.0.0'.
Adding 'polymer 1.0.0' to Eqs.Mvc.Web.
Successfully added 'polymer 1.0.0' to Eqs.Mvc.Web.
PM> Install-Package paper-elements
...long long list of dependency imports
When I try to import paper-elements.html I notice that in paper-elements.html there are missing files and files in the wrong locations.
For example in paper-elements.html:
<link rel="import" href="../polymer/polymer.html">
is actually located in the project at the scripts root:
<link rel="import" href="../polymer.html">
I get a lot of 404 errors. Did I import the packages incorrectly?
Don't use NuGet to get polymer elements (as it's not maintained by Google so it's not up-to-date), use Bower instead.
Prior to ASP.NET 5
Go to NuGet's Package Management Console and install Bower.
PM> Install-Package Bower
Navigate to your web project folder in File Explorer and then Shift + Right Click anywhere to select Open command window here in the context menu.
Inside the command prompt, run the following commands one after another.
bower init
bower install --save Polymer/polymer
bower install --save PolymerElements/paper-elements
Whenever there's a new version, run the following command.
bower update.
ASP.NET 5
It's a lot simpler in ASP.NET 5, since the project already adds a bower.json file for you. So you just need to add the dependencies there -
{
"name": "Portal",
"private": true,
"dependencies": {
"polymer": "^1.1.3",
"paper-elements": "PolymerElements/paper-elements#^1.0.3",
...
}
Once all dependencies are added, go to your Visual Studio web project and enable Show All Files. You will see a folder called bower_components, just include it into your project.
Have a look at this question I asked too.
Alternatively my company, FrostAura Consolidated now manages a package that you might find useful. This package scaffolds all core and paper components with a demo of how to create a custom web component with automated documentation and unit testing. Check it out at https://www.nuget.org/packages/FrostAura.Dynamics.Polymer.Kickstart/
you may need run Set-ExecutionPolicy Unrestricted in windows powershell to allow Bower install scripts to run...

How does kpm manage content folders in a NuGet package?

I'm running Visual Studio 15 Preview, and started a new project: ASP.NET Web Application > ASP.NET 5 Empty. I then opened project.json and modified it to add AngularJS.Core 1.3.4 as follows:
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta1",
"AngularJS.Core": "1.3.4" // I only added this line
},
I see the package downloaded and added to my packages folder, but the nupkg file has a content folder (with the actual *.js files I want added), but those files aren't being added to my project. There are no error messages or warnings of any kind (at least none via the package manager log).
I have also tried running kpm --verbose install ... and kpm --verbose restore via the command line, and I don't see anything useful for solving this.
I know I can manage this manually, but am I missing something? Is this a bug, or am doing this wrong, or are my expectations incorrect? I'm new to this ASP.NET vNext stuff, and this is my first time jumping into it.
It doesn't. KPM currently doesn't do anything with packages that contain content/powershell scripts/transforms etc.

Resources