How to add Target Runtimes to project.json in ASP.Net Core Project

To See how to create a .Net core app, Click here …

First Open the project and you can see there is a JSON file called “project.json”

3-app-created

Then click it and you will see the JSON content in that file.

The default JSON content like below.


{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Routing": "1.0.1",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "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",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},

"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},

"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},

"publishOptions": {
"include": [
"wwwroot",
"**/*.cshtml",
"appsettings.json",
"web.config"
]
},

"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

When we collapse the JSON content, we can see what are the main properties of the file..

12-default-project-json-file

So according to above image, there is no property to declare Target Runtimes.

So We have to add them manually according to our requirement.  I’m using windows based machines, so I’ll add windows operating systems as target runtimes.

13-add-runtimes-to-project-json


"runtimes": {
"win10-x64": {},
"win81-x64": {},
"win8-x64": {},
"win7-x64": {},
"win7-x86": {}
}

When you add this code, you could see the NuGet package references are restoring automatically in the right hand side .

14-restoring-packages

After It has completed, you are ready to publish the app.

Then Right click on the project and click “Publish”.

You will see the Publish window. And Go to the settings menu and you will see those runtimes has added to the target runtimes drop down list.

15-target-runtimes-in-publish

Important.

If you want to delete old published files when you are publishing a new version, Check the

“Delete all existing files prior to publish” check box..

16-delete-existing-files

Thanks !

One thought on “How to add Target Runtimes to project.json in ASP.Net Core Project

  1. Pingback: Fix Error : “Could not find a part of the path” While Publishing ASP.NET Core MVC Application To the Target Platform of Windows 7 x64/x86 | Codez with Buddhima

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s