Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asp.Net project with Build platform x86 #6144

Closed
sadjadbp opened this issue May 17, 2016 · 21 comments
Closed

Asp.Net project with Build platform x86 #6144

sadjadbp opened this issue May 17, 2016 · 21 comments
Milestone

Comments

@sadjadbp
Copy link

Here is a original thread at MVC repo, been told to open it here aspnet/Mvc#4663

I have a asp.net project that reference a native dll via Nuget package. This native DLL is only build for x86. I've changed my project.json to set buildOptions
"platform": "x86"

But when I build this asp.net project via visual studio, it creates "bin\Debug\net46\win7-x64" as oppose to "win7-x86". If I run the resulting ".exe" file it would crash.

I've tried to use "dotnet build -r win7-x86" and it would create the right folder "bin\Debug\net46\win7-x86" and then I can run the ".exe" file.

Still cannot test the application in x86 mode.

Then I've uninstalled Microsoft .NET Code 1.0.0 RC2 - SDK Preview 1 (x64) which was installed via "VS 2015 Tooling Preview" and installed the "x86" one, and everything seems to be working.

I think it is not right. I should be have the option to install x64 and x86 and then via that buildOption I should be able to tell dotnet how to compile. Just like MSBuild and ASP.Net projects where I set the build options from Project Properties.

@guardrex
Copy link
Contributor

@sadjadbp Not sure if it helps, but you could probably publish it: dotnet publish -c Debug -r win7-x86 ... that should work ... if you don't mind publishing over building.

@WolfspiritM
Copy link

WolfspiritM commented May 23, 2016

Having the exact same issue.
I have a ASP.NET project that needs to be build for x86 (I know..this shouldn't be the case anymore...but my website is relying on an x86 C++ project). Whatever I tried it always build for x64. Thanks to the tip uninstalling the x64 version and installing the x86 version fixed it but now I'm stuck to x86 it seems.

@guardrex I tried publishing but for me that also crashed with a BadImageFormatException on launch like build -r x86 did. It maybe packs the x64 librarys while building the project itself for x86.

@sadjadbp
Copy link
Author

@WolfspiritM good that it helped. But yes, now I think you are stuck with x86. Interesting enough, installing the x64 version of Windows Server Tools on our servers, I can copy the published folder there and then Web Application works fine!

Either way, it seems to be VS Tooling bug or something. I'll wait for MS Person to answer to this thread.

@Quinn-L
Copy link

Quinn-L commented May 24, 2016

EDIT: Sorry everyone, this solution doesn't work. See comments further down.

ORIGINAL POST:
I'm having the same issue as well, however I think I've got it working now (maybe).
According to this https://github.com/dotnet/cli/blob/rel/1.0.0/Documentation/specs/runtime-configuration-file.md
you also need to specify the runtime to force the platform properly.
eg. outside next to buildOptions

"runtimes": { "win": [ "win7-x86", "win8-x86", "win10-x86" ] }

Try this to see if Visual Studio will pick this up (you might want to delete the win7-x64 folder first to ensure it rebuilds the project.

@sadjadbp
Copy link
Author

@Quinn-L thanks, that seems to be the fix.

@guardrex
Copy link
Contributor

@sadjadbp are you saying that you were able to get x86 outputs with "platform": "x86" and dotnet build merely by having that runtimes section present?

@sadjadbp
Copy link
Author

@guardrex seems like "platform": "x86" is irrelevant, but just in case I just left it there.
I'm using Visual Studio not the command mode, and but adding what @Quinn-L suggested, I was able to get a win7-x86 build folder and the same goes for publishing via VS. I just installed SDK Preview 1 (x64) back again and removed the SDK Preview 1 (x86) from my PC. Now one project with these new settings would create win7-x86 folder and the other normal project creates a win7-x64 folder as it should.

@WolfspiritM
Copy link

Sorry but I can't get it to work like that.
I removed x86 SDK and installed x64 again, started Visual Studio, created a new "ASP.NET Core Web Application (.NET Framework)" added runtimes beside buildOptions and even added platform so it looks like this:

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "platform": "x86"
  },
  "runtimes": { "win": [ "win7-x86", "win8-x86", "win10-x86" ] },

Then did a build and ended up with a win7-x64 folder.
Same goes for "dotnet build" and it also crashes (as before when using platform x86).
My project.json:
https://gist.github.com/WolfspiritM/df81be9ca3d1d6857ee5d534b032f230
Any ideas?

"dotnet --info" shows:
Product Information:
Version: 1.0.0-preview1-002702
Commit Sha: 6cde21225e

Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64

@sadjadbp
Copy link
Author

@WolfspiritM couple of VS restarts and now mine does not work, it seems to be caching the runtime version! So not fixed for now.

@Quinn-L
Copy link

Quinn-L commented May 24, 2016

Ok, I've restarted my machine like @sadjadbp and now it's no longer working on Visual Studio (ie. it's building against x64 again). Will need to play around more, unless there's a proper solution somewhere...

@Quinn-L
Copy link

Quinn-L commented May 24, 2016

Further research shows that x64 CLI can't build x86 apps https://github.com/dotnet/cli/issues/1485
We are required to install the x86 SDK and get this CLI to build our projects.
So the reason it was originally working in VS on my machine was because I managed to get the x86 CLI as the primary CLI, but on restarting my VS is now with x64 CLI and breaking the build.
Looks like those build settings are kind of pointless then...

@sadjadbp
Copy link
Author

@Quinn-L Seems like whichever SDK you install the first (if you have both), it will be the default. I had x64 uninstalled and x86 installed. Both projects of mine (the one I wanted to be build in x86 and the other one that is fine under x64) was build in x86. Now I installed x64 on top of x86 SDK, and still both projects are compiled in x86 mode! As you said, seem like all those settings in project.json are useless.

They said, they'll move everything back to csproj to be MSBuild compatible in RC3 and forward. Maybe that'll fix our issues.

@TheRealPiotrP
Copy link
Contributor

@barrytang @abpiskunov can you take a look? Where should folks be opening VS Tooling issues?

@sadjadbp
Copy link
Author

aspnet/Tooling#522 @piotrpMSFT I've already added in Tooling

@abpiskunov
Copy link
Contributor

Tooling issue was closed by @sayedihashimi , see his comment here: aspnet/Tooling#522

@sayedihashimi
Copy link
Member

I reopened aspnet/Tooling#522.

@MatLeger
Copy link

MatLeger commented Jul 7, 2016

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"
  }
}

@mafshin
Copy link

mafshin commented Sep 3, 2016

I tried almost all suggestions in this and related issues and they either don't generate any x86 binary or they result in BadFormatException.

As of now, is there any workaround to get a working x86 binary with version 1.0.0-preview2-003121 ?

My API is running well under x64 but I need to get a x86 binary one right now.

@mafshin
Copy link

mafshin commented Sep 13, 2016

I could get it working by running dotnet publish -r win7-x86 with the following configuration

  "runtimes": {
    "win7-x86": {},
    "win7-x64": {}
  },

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

The x86 build works just fine.

@jstensved
Copy link

jstensved commented Apr 3, 2017

For me, changing

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

to

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

Fixed it. I think it is because i'm running in a x64 environment.

@livarcocc
Copy link
Contributor

We are no longer supporting project.json. Please, try these out with the 1.0.1 version of the CLI that supports only MSBuild. If this is still a problem there, please, re-activate this issue.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@msftgits msftgits added this to the Backlog milestone Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests