1

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");
        }
    }
}
svick
  • 236,525
  • 50
  • 385
  • 514
Haukman
  • 3,726
  • 2
  • 21
  • 33
  • While VS integration is still a preview and not mature, you simply asked for something impractical here. – Lex Li Nov 30 '16 at 02:46
  • I'm not sure why you think it's impractical. The publish UI has a drop down to pick which runtime you want to publish for, it just doesn't build for the selected runtime. It seems something is missing or I don't know how to do it. It may be that the answer is that it's impossible due to the current level of the tooling, bug or known issue. But isn't it fair to ask a question about a system that is released (even if it's preview-tagged) and used by a lot of developers? – Haukman Nov 30 '16 at 03:45

1 Answers1

1

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

derwasp
  • 802
  • 8
  • 17
  • 1
    Yes, but win7-x64 generates more dependencies and for deployment to newer servers it would include this extra stuff that isn't needed. I definitely see your point, but my question was more if it was possible to tell VS which one to build for, like adding some property to the project-file or something. I know I can tell which runtime to use with both msbuild and dotnet cli, the question was if it was possible in VS as well. – Haukman Dec 01 '16 at 06:10