0

I have two projects. One must be built with x86 architecture and the other with x64.

In my global.json I specify which architecture I want to use:

"sdk": {
    "version": "1.0.0-preview2-003131",
    "architecture": "x64"
}

Despite this, for the x64 project, I see in the Build Output:

1>  C:\Program Files (x86)\dotnet\dotnet.exe build "C:\websites\myproject".

I can change between having Visual Studio 2015 use C:\Program Files (x86)\dotnet\dotnet.exe and C:\Program Files\dotnet\dotnet.exe by changing the order of my environment variables (as noted here). But I was hoping there was a way Visual Studio could just select the right version with having to change environment variable order.

Any ideas?

John-Luke Laue
  • 3,736
  • 3
  • 32
  • 60
  • This option is actually use for the dotnet SDK/tooling, i.e. when you run `dotnet run` then the version and architecture will determine if the ´dotnet` exe is executed from `C:\Program Files\dotnet` (x64) or `C:\Program Files (x86)\dotnet` (x86) as well as choose the correct tooling version in the sdk to use (inside the "sdk" folder in the respective dotnet locations (see above) – Tseng Jun 15 '17 at 23:33
  • @Tseng Interesting. But when I change the architecture to x86 or x64, Visual Studio doesn't care. It always seems to choose whatever is first in my PATH (which is currently ''C:\Program files (x86)\dotnet'') – John-Luke Laue Jun 15 '17 at 23:44
  • You misread my comment. I didn't said that Visual Studio or the compiler use this value! `global.json` is only used by the **Command Line command dotnet**, it do not change compile architecture. You can see that on the tag name which is `sdk`, not `runtime` or `compile` or anything like that. Run `dotnet --version` inside of your project and it should display `Version: 1.0.0-preview2-003131` when you run it **outside** of the folder with the global.json (i.e. on C:\), then it will say `Version: 1.0.4` or whatever is the newest installed SDK for you. That's all it does – Tseng Jun 16 '17 at 06:06
  • If you want 64 bit output you need to change the build settings in your csproj/project properties. In the past there were some issues if both x64 and x86 runtime being installed that only the last one worked, dunno if thats fixed now but unless you have native x64-only dependencies, it doesnt really matter which one you compile to as C# compiles to the same CL instruction) – Tseng Jun 16 '17 at 06:08
  • But iirc if you have multiple runtimes defined in your project.json it will also create the appropriate folders inside the `bin\Debug\\` folder, i.e. `bin\Debug\net462\win7-x64\`. But I stopped using VS2015 the day 2017 hit RTM – Tseng Jun 16 '17 at 08:05
  • [This issue](https://github.com/dotnet/cli/issues/3387#issuecomment-248360943) may also be relevant for you which states _With MSBuild projects, you will no longer build for a specific runtime/RID. Instead, `dotnet build` and `dotnet run` will always build portable apps. When you `dotnet publish`, you will get to pick that you want a self-contained app for a specific RID._ and https://stackoverflow.com/a/40652794/455493 – Tseng Jun 16 '17 at 08:21

1 Answers1

0

Visual Studio will always run your app in 32-bit because Visual Studio itself and the tooling is 32-bit.

When you publish your app however, it'll use the 64-bit sdk and so once deployed, it will run in 64-bit.

As alternative, you can use dotnet-watch if you really need it to run in 64-bit when developing.

Usually though, you don't really need 64-bit and running 32-bit especially in Azure could actually save you money.

Dealdiane
  • 3,984
  • 1
  • 24
  • 35