I am attempting to use the new Class Library (Package) project in VS 2015.
I would like to target dnx451, so my package.json looks like this:
{
"version": "1.0.0-beta-1",
"description": "Foo",
"authors": [ "Foo" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Newtonsoft.Json": "8.0.1",
"Microsoft.AspNet.Razor": "4.0.0-rc1-final",
"Microsoft.Extensions.Configuration": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc1-final",
"System.Net.Http": "4.0.1-beta-23516"
},
"frameworks": {
"dnx451": { }
}
}
Build is fine, and I get:
Recaptcha-dnxcore -> C:\Users\Epic\Documents\artifacts\bin\Foo\Release\Foo.1.0.0-beta-1.nupkg
Now I create a web project and edit its project.json file so that it targets only the dnx451 framework:
"frameworks": {
"dnx451": { }
},
When I add a reference to my Foo package, I get an error:
The dependency Foo 1.0.0-beta-1 in project WebApplication7 does not support framework DNX,Version=v4.5.1.
How can I create a Nuget package from a Class Library (Package) project that supports dnx451?
Per the comment below, here is the full project.json of the web app:
{
"userSecretsId": "aspnet5-WebApplication7-0b4c05f0-6435-486b-9738-1b6aa3daee2c",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"System.Net.Http": "4.0.1-beta-23516",
"Foo": "1.0.0-beta-1"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": { }
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
I followed the same procedure as mentioned in your question
I created both class library and web project in same solution, everything worked fine.
Since your are more focused on making it NuGet package target to dnx451. I created another web application in separate solution, yes it throws errors because NuGet packages named are many "Foo". I guess due to this restoring of packages is given issue as its referring to Global NuGet feed.
Then I tried referring "Foo" Nuget package locally using this link How to install a Nuget Package .nupkg file locally?
Ensure that newly create local Package Source should be on TOP and Offical NuGet second place.
After this, I restored web application in separate solution, it build fine and run properly also. Even I installed this NUGET in Console apps also
Hope this works out.
The class library should also have it's own project.json and define the frameworks that it supports:
"frameworks": {
"dnx451": { }
}
Don't add the version Number if you add a reference to a project, because it will search for the package on any Nugget feed.
Just add a reference to Foo, like this:
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"System.Net.Http": "4.0.1-beta-23516",
"Foo": ""
},
Have a look at this answer.
You can only add a direct reference to your class library project only if both projects are in the same solution.
If your projects are not in the same solution you have to go to your class library project properties, open Build tab and check Produce outputs on build option
NuGet package will be created in {SolutionDir}\artifacts\bin{ProjectName}{Configuration} directory on each project build.
To use the library, publish NuGet package to nuget.org or any other NuGet feed and add it to your project using Visual Studio (References ~> Manage NuGet Packages...) or to dependencies property in project.json.
Related
I am getting following error while running the publish asp.net core RC1 website on the Windows Server using web.cmd,
Unable to load application or execute command 'Microsoft.AspNet.Server.Kestrel'
The publish website has runtime included.
Here is my project.json file,
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"DocX": "1.0.0.19",
"EntityFramework": "6.1.3",
"EntityFramework.Core": "7.0.0-rc1-final",
"iTextSharp": "5.5.9",
"itextsharp.pdfa": "5.5.9",
"itextsharp.xtra": "5.5.8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.Net.Http": "2.2.22",
"Newtonsoft.Json": "8.0.3"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": {
"dependencies": {
"WebApi.Core": "1.0.0-*"
},
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Drawing": "4.0.0.0",
"System.Messaging": "4.0.0.0",
"System.Transactions": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
The publish content has a dependency 'WebApi.Core' which is added as a nuget package. Actually its a another class library project in my solution.
I have tried dnu restore but it is giving problem for the WebApi.Core dependency.
Same publish content is running fine on my Windows 10 local machine.
Please let me know if you guys have any solution to resolve this problem.
Try deleting the global.json file from the hosted folder. It would be at approot or at approot\src[projectName].
If that doesn't work, try running the commands dnu list, dnu restore, dnu build
as per this:
https://stackoverflow.com/a/34212116/2168359
We try to host an ASP.Net core MVC RC1 DNX project on Service Fabric. The deployment works but the project is not starting. According to our log it seems service fabric cannot find the startup class and create an instance. We downloaded a demo project that works fine, but we cannot bring our project up and running. We cannot see any peace of helpful log information. Not in event log, service fabric log stream or with visual studio debug prompt. Is there anything we can do to enable more debug information. What could be wrong on our configuration, or project setup? This are the Key parts of our project:
ServiceManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<ServiceManifest Name="WebPkg"
Version="1.0.0"
xmlns="http://schemas.microsoft.com/2011/01/fabric"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ServiceTypes>
<StatelessServiceType ServiceTypeName="WebType" >
<Extensions>
<Extension Name="__GeneratedServiceType__">
<GeneratedNames xmlns="http://schemas.microsoft.com/2015/03/fabact-no-schema">
<DefaultService Name="WebTypeService" />
<ServiceEndpoint Name="WebTypeEndpoint" />
</GeneratedNames>
</Extension>
</Extensions>
</StatelessServiceType>
</ServiceTypes>
<CodePackage Name="C" Version="1.0.0">
<EntryPoint>
<ExeHost>
<Program>approot\runtimes\dnx-clr-win-x64.1.0.0-rc1-update2\bin\dnx.exe</Program>
<Arguments>--appbase approot\src\Sportflash.Web Microsoft.Dnx.ApplicationHost Microsoft.ServiceFabric.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel</Arguments>
<WorkingFolder>CodePackage</WorkingFolder>
<ConsoleRedirection FileRetentionCount="5" FileMaxSizeInKb="2048" />
</ExeHost>
</EntryPoint>
</CodePackage>
<Resources>
<Endpoints>
<Endpoint Protocol="http" Name="WebTypeEndpoint" Type="Input" Port="5000" />
</Endpoints>
</Resources>
</ServiceManifest>
project.json:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework": "6.1.3",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Google": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.ServiceFabric.AspNet.Hosting": "1.0.0-rc1",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"Sportflash.Web.Core": "1.0.0-*",
"Microsoft.ApplicationInsights.AspNet": "1.0.0-rc1",
"angular-signalr-hub.TypeScript.DefinitelyTyped": "0.6.7",
"Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Globalization.CultureInfoCache": "1.0.0-rc1-final",
"Microsoft.Extensions.Localization.Abstractions": "1.0.0-rc1-final",
"Microsoft.AspNet.Localization": "1.0.0-rc1-final",
"Microsoft.Extensions.Localization": "1.0.0-rc1-final",
"jquery.TypeScript.DefinitelyTyped": "2.8.8",
"signalr.TypeScript.DefinitelyTyped": "0.2.0",
"Newtonsoft.Json": "8.0.3",
"Microsoft.CodeAnalysis": "1.1.0-rc1-20151109-01"
},
"userSecretsId": "aspnet5-Sportflash.Web-f067f2f7-086e-4a52-88ea-a7317d1b11e8",
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"gen": "Microsoft.Extensions.CodeGeneration"
},
"frameworks": {
"dnx451": {
"dependencies": {
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components",
"PackageRoot"
],
"publishExclude": [
"node_modules",
"bower_components",
"PackageRoot",
"**.user",
"**.vspscc"
],
"scripts": {
"postrestore": [ "npm install", "bower install" ],
"prepublish": [ "npm install", "bower install" ]
}
}
Startup.cs:
public class Startup
{
public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}
I will suggest to explore this example on GitHub.
This example demonstrates how ASP.NET Core can be used in a communication listener of stateless/stateful services.
This example is updated to use dotnet cli.
There are 2 different branches dnx and dotnetcli. dnx branch can be used inside Visual Studio.
UPDATED
I have published my solution to an azure web app. No errors arose, but when I browse to the page it doesn't display at all (a GET request is issued but the server does not respond for a long time and eventually returns a 500 error).
I think the problem might be that dnx is listening on http://localhost:5000, which is obviously not the Azure app site.
I deduced this by opening a Kudu debug console, and then running site\approot\web.cmd, which generates the following output:
info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
Azure Web Sites environment detected. Using 'D:\home\ASP.NET\DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
But I can't work out how to change this. I have searched my entire source code and the environment variables, and the only reference to localhost is in Properties/launchSettings.json:
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55071/",
"sslPort": 44391
Here are what appear to be the relevant files:
global.json:
{
"projects": [
"src"
],
"sdk": {
"version": "1.0.0-rc1-update1"
},
"packages": "packages"
}
Project.json:
{
"userSecretsId": "aspnet5-Kado-#######",
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-rc1-final",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-rc1-final",
"Microsoft.Extensions.CodeGenerators.Mvc": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.UserSecrets": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-rc1-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
"Microsoft.jQuery.Unobtrusive.Ajax": "3.2.3",
"System.Runtime": "4.0.21-beta-23516",
"Bootstrap.Datepicker": "1.6.0",
"bootstrap-select": "1.10.0",
"Newtonsoft.Json": "8.0.2",
"Stripe.net": "6.0.1",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-rc1-final",
"Microsoft.AspNet.Authentication.Google": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnxcore50": {
"dependencies": {
"System.ComponentModel.Annotations": "4.0.11-beta-23516"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
Startup.cs includes the following code:
app.UseIISPlatformHandler(options => options.AuthenticationDescriptions.Clear());
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
</handlers>
<httpPlatform processPath="%DNX_PATH%" arguments="%DNX_ARGS%" stdoutLogEnabled="false" startupTimeLimit="3600"/>
</system.webServer>
</configuration>
I have a PCL with this project.json:
{
"supports": {
"net46.app": {},
"uwp.10.0.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0",
"System.ServiceModel.Primitives": "4.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452+win81"
}
}
}
When I add a reference to my asp.net 5 web app, the resulting web app's project.json looks like this:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": {
"dependencies": {
"MyPcl": "1.0.0-*"
}
},
"dnxcore50": {
"dependencies": {
"MyPcl": "1.0.0-*"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Which from what I can tell should be correct, but it results in a couple of errors in the web app:
Predefined type 'System.Object' is not defined or imported MyWebApp.DNX 4.5.1 C:\source\MyWebAppStartup.cs
Predefined type 'System.Void' is not defined or imported MyWebApp.DNX 4.5.1 C:\source\MyWebApp\Startup.cs
Ive found 100 ways to fix this, none have worked, and Im just not getting it. Any help would be appreciated. (Im using VS2015)
EDIT: Restarting VS resolved those errors. Now there is only this error
Object reference not set to an instance of an object. MyWebApp C:\source\MyWebApp\DNX 1
Im trying to get remote IP address in Asp.net Vnext.
after i added this line in my code , the page stopped working in published IIS
server (no error appears , only white screen) :
var remoteIpAddress = HttpContext.Features.Get<IHttpConnectionFeature>()?.RemoteIpAddress;
also when i checked the result in local IIS-Express it gives me this :
this my project.json file :
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.FileProviderExtensions": "1.0.0-rc1-final",
"Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"DataAccessComponents": "1.0.0-*",
"Utility": "1.0.0-*",
"AdModels": "1.0.0-*",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.Net.Http": "2.2.22",
"Newtonsoft.Json": "7.0.1",
"Microsoft.AspNet.Http.Abstractions": "1.0.0-rc1-final",
"System.Net.Http": "4.0.1-beta-23516",
"System.Net.Primitives": "4.0.11-beta-23516",
"System.Text.Encoding": "4.0.11-beta-23516",
"Microsoft.AspNet.WebApi.Client": "5.2.3",
"Microsoft.AspNet.Http.Extensions": "1.0.0-rc1-final",
"Microsoft.Dnx.Compilation.Abstractions": "1.0.0-rc1-final",
"Microsoft.AspNet.Http.Features": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta7"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.Data": "4.0.0.0",
"System.Net.Http.WebRequest": "4.0.0.0",
"System.Web": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Also im using normal IIS 8 for my project and im not gonna port this program to another OS.
should i change the "Web" Section in project json ? Like adding iis or something ?