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
Related
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.
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.
I created a VS 2015 U3 solution that contains a netstandard1.3 PCL library X and a netcoreapp1.0 test library Y. I'm using MSTest (dotnet-test-mstest and MSTest.TestFramework).
This is src\X\project.json:
{
"supports": {},
"dependencies": {
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": {}
}
}
This is test\Y\project.json:
{
"version": "1.0.0-*",
"testRunner": "mstest",
"dependencies": {
"Microsoft.NETCore.App": "1.0.0",
"dotnet-test-mstest": "1.0.1-preview",
"MSTest.TestFramework": "1.0.0-preview",
"X": { "target": "project" }
},
"frameworks": {
"netcoreapp1.0": {
"imports": [ "dnxcore50", "portable-net45+win8" ]
}
},
"runtimes": {
"win8-x64": {}
}
}
It turned out that I need to have this last
"runtimes": {
"win8-x64": {}
}
in Y\project.json, otherwise I get the following error:
_dotnet-test Error: 0 : System.InvalidOperationException: Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win81-x64, win8-x64, win7-x64'._
Why is that? Can't I have a generic test app that will work everywhere if I install the SDK?
I created an empty asp.net web application project with rc2. My project file is:
{
"testRunner": "xunit",
"dependencies": {
"xunit": "2.1.0",
"dotnet-test-xunit": "1.0.0-rc2-build10025",
"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
"type": "platform"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.Cors": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": {
"version": "1.0.0-preview1-final",
"imports": "portable-net45+win8+dnxcore50"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"gcServer": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
Now I want to add HttpConfiguration config = new HttpConfiguration(); in my unit test.
But HtppConfiguration is from ASP.NET WEB API 2. How to change my project.json file? Or is there any replacement for it in ASP.NET CORE RC2?
ASP.Core provides an easy way for integration testing using TestServer class. The following may help to start using it:
an ASP.Net Core documentation about integration testing.
a post about using TestServer with example on github.
a TestServerTests.cs file from Hosting repo, that contains xunit tests for TestServer. May help to review, what TestServer can do.
good question on SO: "Why the TestServer (AspNetCore) gives 404 error on static files?"
and keep in mind that a lot of projects in https://github.com/aspnet use TestServer for testing (like Diagnostics ).
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