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 ).
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.
I'm trying to debug a NETCore project in VS Code but launching the debugger gives me the following error:
MSBUILD : error MSB4025: The project file could not be loaded.
Data at the root level is invalid. Line 1, position 1.
c:\path\to\my\project.json
project.json content:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": "dnxcore50"
}
}
}
Any ideas?
Turned out that the project.json format is not longer supported. More info here on GitHub.
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
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 have ASP.NET Core project which has both netcoreapp and net46 in frameworks section. I can build and run it without any problem on Mac OS X. But when i open it in VSCode it shows tons of errors like this: Predefined type '...' is not defined or imported [net46] and everything is red.
Is there any way to fix it without removing net46 from project.json?
Frameworks section of my project.json:
"frameworks": {
"net46": {
"dependencies": {
"System.Net.Http": "4.0.0-*"
}
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0-*",
"type": "platform"
},
"System.Net.Http": "4.0.1-*"
},
"imports": [
"dnxcore50"
]
}
}