Upgrading Asp.Net Web API from RC1 - asp.net-web-api

We are in process of building a new WebApi. We started out with using .Net Core Rc1 before summer holidays - and now, with .Net Core being 1.0 I would like to update.
But I run into some issues - which I can't figure out if I can solve?
The challenge is that I need to reference some .Net 4.5.1 x86 assemblies.
This means I need to use a moniker that allows use of .Net 4.5.1 - and if I need both worlds, as I understand it - only netstandard16 is available. (https://learn.microsoft.com/da-dk/dotnet/articles/standard/library)
But then I run into the issue that .Net 4.6.3 (or vNext in the above link) is not available yet.
If I reference netstandard15 - then AspNetCore libraries won't work.
If I reference netstandard16 - then I get the following errors
error : Can not find runtime target for framework '.NETStandard,Version=v1.6' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes:
error : 1. The project has not been restored or restore failed - run `dotnet restore`
error : 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section.
error : 3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute libraries.
Is it at all possible with current available bits to do the following
Have a business layer in .Net 4.5 compiled for x86 (need to reuse this - legacy is great)
Create a Asp.Net Core site
Reference the business Layer in site - and just carry on coding
Is anyone able to help me out here?
EDIT: The project.json (in two versions)
From RC1
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"AutoMapper": "4.2.1",
"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",
"Swashbuckle.SwaggerUi": "6.0.0-rc1-final",
"Swashbuckle.SwaggerGen": "6.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx451": {
"dependencies": {
"BaseClasses": "1.0.0-*",
"DatabaseAccessCS": "1.0.0-*",
"BusinessLogic": "1.0.0-*",
"StandardFunctionsCS": "1.0.0-*"
},
"frameworkAssemblies": {
"System.configuration": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
The attempt on final 1.0 that came closest to working
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {
"AutoMapper": "5.1.1",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.Core": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Swashbuckle.SwaggerGen": "6.0.0-beta902",
"Swashbuckle.SwaggerUi": "6.0.0-beta902"
},
"frameworks": {
"netstandard16": {
"dependencies": {
"BaseClasses": {
"target": "project"
},
"DatabaseAccessCS": {
"target": "project"
},
"BusinessLogic": {
"target": "project"
},
"StandardFunctionsCS": {
"target": "project"
}
}
}
}
}
Final json that works
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"platform": "x86"
},
"runtimes": {
"win": ["win7-x86", "win8-x86", "win10-x86"]
},
"dependencies": {
"AutoMapper": "5.1.1",
"LogiholdBusinessObjects": "5.5.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.Core": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Swashbuckle.SwaggerGen": "6.0.0-beta902",
"Swashbuckle.SwaggerUi": "6.0.0-beta902"
},
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Configuration": "4.0.0.0"
}
}
}
}

If you want a .NET Core appliction, you should use the netcoreapp1.0 target framework. You probably won't be able to reference the .NET 4.5.1 library in the .NET Core app.
You could also target a desktop (full) .NET Framework like this:
"frameworks": {
"net451": { }
}
Now you can use .NET 4.5.1 library but your application won't run on the .NET Core runtime anymore.
You could also target a higher version of .NET, just like `net461 for example.

Related

How to cloud build my app while PlayServices is using AndroidX?

Today, I created a new project, installed some plugins and tap on "Run" in NativeScript Sidekick, to build my app on cloud to my Android device, but I faced this error:
[00:01:35.796] [WARN] Attribute application#appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91
is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:8:5-18:19 to override.
FAILURE: Build failed with an exception.
Some said that NativeScript Sidekick and NativeScript Cloud build are not yet compatible with NativeScript 6
I have been navigating for hours and reading similar issues on GitHub and Stack Overflow, but none of them worked for me, or for Cloud build.
This is my package.json content:
{
"nativescript": {
"id": "com.app.test",
"tns-android": {
"version": "5.4.0"
},
"tns-ios": {
"version": "5.4.2"
}
},
"description": "NativeScript Application",
"license": "SEE LICENSE IN <your-license-filename>",
"repository": "<fill-your-repository-here>",
"dependencies": {
"nativescript-geolocation": "5.1.0",
"nativescript-mapbox": "4.4.1",
"nativescript-plugin-firebase": "9.0.3",
"nativescript-theme-core": "1.0.6",
"nativescript-ui-autocomplete": "5.0.0",
"nativescript-ui-dataform": "5.0.0",
"nativescript-ui-listview": "7.0.1",
"nativescript-ui-sidedrawer": "7.0.0",
"nativescript-webrtc-plugin": "2.0.0-alpha.18",
"tns-core-modules": "5.4.3"
},
"devDependencies": {
"nativescript-dev-typescript": "~0.10.0",
"nativescript-dev-webpack": "~0.24.0"
},
"gitHead": "**************",
"readme": "NativeScript Application",
"author": "***"
}
Edit
I am not using NS 6, I use NS 5, since Sidekick is not yet compatible with NS 6. Also, I removed UI Pro components plugins, and it seems to work now. The pro UI plugins might work if I use older versions.
I'm not sure the compatibility of SideKick/Cloud build and 6.0/AndroidX, that normally lags a couple weeks. However I can tell you based on your package file, that it won't work. You are mixing Android & AndroidX :)
NativeScript requires NS 6.0 runtimes for AndroidX. NS 5.4 DOES not use AndroidX. But you are using NS-UI versions which are AndroidX.
So to test if sidekick/cloud builds supports AndroidX I would make the following changes:
{
"nativescript": {
"id": "com.app.test",
"tns-android": {
"version": "5.4.0"
},
"tns-ios": {
"version": "5.4.2"
}
},
Needs to be changed to
{
"nativescript": {
"id": "com.app.test",
"tns-android": {
"version": "6.0.0"
},
"tns-ios": {
"version": "6.0.1"
}
},
In addition this needs to be changed:
"devDependencies": {
"nativescript-dev-typescript": "~0.10.0",
"nativescript-dev-webpack": "~0.24.0"
},
to
"devDependencies": {
"nativescript-dev-webpack": "~1.0.1"
},
And finally this:
"tns-core-modules": "5.4.3"
needs to be
"tns-core-modules": "~6.0.1"
As for the rest of the dependencies; that is hard to say; because NativeScript just transitioned to AndroidX; their is a good change that some of the other plugins you have listed; might not be AndroidX compatible. I would honestly try building an app with out any of the extra plugins first:
"dependencies": {
"nativescript-theme-core": "1.0.6",
"tns-core-modules": "~6.0.0"
},

Getting error Microsoft.AspNetCore.MVC 1.1.0 does not support framework .NETCoreApp, Version v1.1

Trying to start an .Net CORE project with MVC. Attempting to use the latest version of .Net CORE (v1.1) and I cannot get a version of MVC to work as a dependency. Below is my project.json file.
{
"buildOptions": {
"emitEntryPoint": true,
"debugType": "portable",
"preserveCompilationContext": true
},
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.1.0",
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.StaticFiles": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0"
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
},
"imports": [
"dnxcore50"
]
}
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"runtimeOptions": {
"gcServer": true
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Gives this error:
The dependency Microsoft.AspNetCore.Mvc 1.1.0 does not support framework .NETCoreApp,Version=v1.1
Just install runtime (not only SDK) from here: https://www.microsoft.com/net/download/core#/current/runtime.
Maybe you'll need execute "dotnet restore" command.
It helps to me.

Where ByteRangeStreamContent class in asp.net core?

I start writing project on asp.net core and I can not find class ByteRangeStreamContent.
Where is it?
Did it was removed from asp.net core?
Is there replacement of this class?
UPDATE 2016-10-06
dotnet --version
1.0.0-preview2-003131
Instead of using ByteRangeStreamContent you can now use the FileStreamResult or FileContentResult and set EnableRangeProcessing to true.
new FileStreamResult(new MemoryStream(bytes), new MediaTypeHeaderValue("audio/mp3"))
{
EnableRangeProcessing = true
};
Add this dependency in your project.json:
"Microsoft.AspNet.WebApi.Client": "5.2.2"
Then, you can use the class:
System.Net.Http.ByteRangeStreamContent
Another option is to write ByteRangeStreamContent to import automatically using Visual Studio:
My project.json is (the default when creating a new web api project):
{
"dependencies": {
"Microsoft.AspNet.WebApi.Client": "5.2.2",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"net461": { }
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
My dotnet version is the following:
C:\Users\fabriciopombo>dotnet --version
1.0.0-preview2-003121
And I'm using Visual Studio 2015 Update 3

Dependency issue with System.Net.Http and ASP.NET 5 on OS X

I am trying to create first sample application running with ASP.NET 5 on OS X. However I just can't figure out how project.json dependencies work.
I generated Web Api Application with yeoman and everything had worked fine until I've tried to use WebClient.
According to dnvm list I'm running:
* 1.0.0-rc1-update2 mono linux/osx
And while restore packages goes well the project fails at build step.
Here is my project.json file:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"tooling": {
"defaultNamespace": "LocationService"
},
"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.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": {
"System.Web.Http": "4.0.0"
}
},
"dnxcore50": {
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
And project fails on build with unresolved reference:
LocationService/Controllers/ValuesController.cs(32,40):
DNXCore,Version=v5.0 error CS0246: The type or namespace name
'WebClient' could not be found (are you missing a using directive or an
assembly reference?)
I've tried add dependency both under dnxcore50 and dnx451.
Dmvm tells me that I can use coreclr x64 but it seems just not works in my case - ends up with numerous unresolved references during build.
WebClient is not available (yet?) for dnxcore.
Try removing dnxcore50 framework or use HttpClient or HttpWebRequest instead of WebClient.

Referencing a ASP.NET Core application in Class Library project

I have created a ASP.NET Core application:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Core": "7.0.0-beta8",
"EntityFramework.SqlServer.Design": "7.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Abstractions": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.DataAnnotations": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"System.IdentityModel.Tokens.Jwt": "5.0.0-rc1-211161024",
"Microsoft.IdentityModel.Protocols": "2.0.0-rc1-211161024",
"ClassLibrary1": "1.0.0-*",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
"Microsoft.AspNet.Identity.Owin": "2.2.1",
"Microsoft.AspNet.WebApi.Owin": "5.2.3",
"Microsoft.Owin.Cors": "3.0.1",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Owin": "1.0.0",
"Thinktecture.IdentityModel": "3.6.1",
"Thinktecture.IdentityModel.Client": "4.0.1"
},
"frameworkAssemblies": {
"System.Web": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
Then I added a unit test project:
{
"version": "1.0.0-*",
"description": "InviteMoi.Test Class Library",
"authors": [ "lamloumiafif" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"dependencies": {
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
},
"dependencies": {
"NUnit": "3.2.1",
"EntityFramework.InMemory": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
}
}
The problem is when I'd like to add the reference of the web application in the test project, it didn't work and an exception indicates that the version of the ASP.NET Core can't be higher appears.
So how can I fix this issue?
in your unit test project.son remove dotnet5.4 and change net451 to dnx451 like it is in the application. unit test projects are applications in the same way that web apps are

Resources