Build does not honor the runtime setting
Steps to reproduce
On X64 machine run:
dotnet build -c release -r win7-x86
Expected behavior
It should generate x86 assemblies
Actual behavior
Generates x64 instead
Environment data
dotnet --info output:
.NET Command Line Tools (1.0.0-preview1-002702)
Product Information: Version: 1.0.0-preview1-002702 Commit Sha: 6cde21225e
Runtime Environment: OS Name: Windows OS Version: 10.0.14352 OS Platform: Windows RID: win10-x64
@ahumeniy See: https://github.com/dotnet/cli/issues/3091#issuecomment-221621415
You prob need to uninstall x64 and install x86. They mention an open tooling issue, so they're aware of the problem.
I had both installed and dotnet is not respecting this in anyway. The tooling isn't ready either. Wherever I add the platform it always generates the one which is installed or x64 if both are installed. This is problem for publish also, because it looks for the wrong folder in the build folder.
I think they'll be fixing it under https://github.com/aspnet/Tooling/issues/522, and they'll update there as they make progress with it.
@ahumeniy can you share a more complete repro? What project are you building?
@piotrpMSFT It's just like the linked issue. If I work in a machine with Windows 10 x64, the MSI for .NET Core SDK install the 64-bit tools and there's no way to build the project into 32-bit. This happens at least when I create a ASP.NET Core project using the .NET Framework only and not .NET Core (I'm using a library not available for .NET Core, that's why).
I tried adding the "win7-x86" runtime but it doesn't work. It even creates the corresponding folder and put the binaries there put it's all 64-bit. I also tried setting the architecture on Visual Studio but still builds 64-bit. When I copy the binaries to a x86 VM I get the error about program not compatible with the processor architecture.
I created a virtual machine running Windows 10 x86 and all development tools and the opposite happens there: The project builds only on 32-bit mode no matter what I do.
I published the project here on GitHub if you want to check out.
https://github.com/ahumeniy/RawPrintService
Also, this happens with ASPNet Core projects only. Classic .NET projects and UWP projects compile fine with the corresponding architecture.
I have the same problem. CLI always creates x64 binaries, no matter what platform specified in project.json buildOptions section. If I run command dotnet build --runtime test, it creates folder called "test" and puts there x64 binaries, is it ok?
This is essentially a dupe of dotnet/sdk#5631
If I understand correctly. The problem is that dotnet build copies the host from the currently installed sdk. You should be able to use dotnet publish --runtime to get what you are looking for.
I can reproduce the same problem with ASP.NET Core 1.0 and Visual Studio 2015 Update 3. The easiest way to reproduce this is to open Visual Studio and create a new ASP.NET Core Web Application (.NET Framework) project and select the "Empty" project template. Run the project without making any changes and verify that the "Hello World!" web page is shown. Note that the folder /bin/Debug/net452/win7-x64 is created.
Now stop the web app, delete the Debug folder and then open project.json and add "platfrom": "x86" to the buildOptions section:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true,
"platform": "x86"
},
Run the application again and this time a System.AggregateException is thrown from Microsoft.AspNetCore.Server.Kestrel.dll when host.Run() is called in Program.cs.
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run(); // <= this throws an exception when platform is set to x86
}
}
Also note that the /bin/Debug/net452/win7-x64 is created instead of /bin/Debug/net452/win7-x86.
For completeness here is what my global.json file looks like:
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003121"
}
}
Closing with the move to MSBuild. 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.
@eerhardt Could you please specify what do you mean by "you will no longer build for a specific runtime/RID" and "dotnet run will always build portable apps"?
I'm creating a NuGet package to use internally in my company and I need a specified RID otherwise I could not deploy proper native DLLs to the runtime folder
I have the architecture
runtimes
win-x64
native
xxx.dll
runtimes
win-x86
native
xxx.dll
So far only this works:
runtimes
win
native
xxx.dll
Because Visual Studio always run the app as AnyCPU.
We should keep the feature to be allowed to specify the RID and the CLI should respect it. If there is no more this then what? NuGet will always choose AnyCPU for DLLs to extract... (like it is now due to this bug).
@koenigsbier can you share a stripped down version of the app?
I think this is the confusion, but seeing an actual project.json will disambiguate for me:
- You are building a portable netcoreapp1.0 application. The application does not have an inherrent CPU architecture affinity
- You would like for that application to be executed in a 64-bit process
We need to provide better UX around this in the CLI.
- If a project is Portable and will run against the active CLI then --runtime should not be permitted.
- If a project is Portable with RID-specific assets and those assets are not available for the current RID then we should fail gracefully
- If a project is Standalone and not targetting the current RID then we should fail gracefully
Ideally, we would also provide useful guidance e.g. The CLI on your path is a 32-bit CLI and you're trying to run a 64-bit application. Do {instructions} to run this application.
The interactions here are certainly confusing and we need to do more to communicate what is going on.
@piotrpMSFT sorry there was still lots of mystery with CLI, Visual Studio and NuGet on my side. You should probably read this. Even though I finally got the solution of my issue, there is lots of things in that process that I don't think are legit.
There is probably some issues (or I need to dig more in that part to understand why they are not issues)
Thanks for the link. I bet we have docs on how this is supposed to work. @blackdwarf @rrelyea can you share pointers?