Reputation: 3776
How can I tell Visual Studio to build against multiple runtimes?
I've created a simple .NET Core (1.0) console application (Hello World with HTTP download). I want to build it for multiple RIDs (win7-x64, win10-x64, etc) so that I can publish it and include the dependencies for a stand-alone application running on Windows 2008 R2 (win7-x64). But my developer machine where I'm building this is Windows 10, so VS picks win10-x64 so my publish task doesn't find any files for win7-x64. I also want to build specifically for win10-x64, so even if I can force it by removing the rest of the RIDs, I want the option to build against multiple.
I know I can do this with MSBuild and dotnet cli, but I'd like to know how to do it from within VS.
project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": "1.1.0",
"System.Net.Http": "4.1.0"
},
"runtimes": {
"win10-x64": {},
"win81-x64": {},
"win8-x64": {},
"win7-x64": {}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Note that I'm using System.Net.Http which requires different dependencies in win7 vs win10 to test. If I run the win10-x64 on Win2k8 then it will fail because it's missing dependencies for the runtime on win7.
It shouldn't matter, but for reference here's the main code block, program.cs:
using System;
namespace TestOnWindows2008
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World");
using (var httpClient = new System.Net.Http.HttpClient())
{
string result = httpClient.GetStringAsync("https://www.microsoft.com/en-us/").Result;
Console.WriteLine(result.Substring(0, 200));
}
Console.WriteLine("Done");
}
}
}
Upvotes: 1
Views: 2042
Reputation: 822
Although I am not directly answering your question, maybe it will help you.
Since your target platform is win7-x64
, which is older than your development platform, win10-x64
, you can keep only win7-x64
and use it for both debugging and publishing.
I've just tested you code using Windows 10 x64 Enterprise and everything went ok.
project.json
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": "1.1.0",
"System.Net.Http": "4.1.0"
},
"runtimes": {
"win7-x64": {}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
And Program.cs
is the one from your question.
Here is the output:
for run
:
C:\temp\test2>dotnet restore && dotnet run
log : Restoring packages for C:\temp\test2\project.json...
log : Writing lock file to disk. Path: C:\temp\test2\project.lock.json
log : C:\temp\test2\project.json
log : Restore completed in 2603ms.
Project test2 (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling test2 for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s) 0 Error(s)
Time elapsed 00:00:01.7257991
Hello World
Done
And for publish
C:\temp\test2>dotnet publish
Publishing test2 for .NETCoreApp,Version=v1.0/win7-x64
Project test2 (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
publish: Published to C:\temp\test2\bin\Debug\netcoreapp1.0\win7-x64\publish
Published 1/1 projects successfully
Upvotes: 1