16

Initially, I created a console application using Mass Transit as my service bus. Recently, I switched to NServiceBus, which doesn't require you to make a console application, but a class library instead. In the project properties, I simply switched the setting that changes it from a console application to a library, but the constraint that you can only build it for x86 is still in effect.

I can't change the build type to Any CPU now that it is a console application, which should now be valid. Is there any way to completely change my application to a class library so that I can run the build Any CPU option? Do I need to create a new project, copy files into it and continue that way? Or is it as simple as changing something in the project (.proj) file?

The Stack Overflow question Missing Debug|Any CPU build configuration for projects and defaulting to Debug|x86 on Windows x64 gives more context around this issue of x86 only for console applications.

Community
  • 1
  • 1
Ryan Hayes
  • 5,290
  • 4
  • 42
  • 52
  • You are battling a very basically dumb design decision in VS2010, every project you add to your solution defaults to a platform target of x86. Even class libraries, the kind that have no say over what the EXE project selected. Just flip the setting back to AnyCPU. – Hans Passant Nov 30 '11 at 23:22
  • 2
    @Hans... no, only projects that generate EXEs default to x86, because MS has determined that architecture-neutral EXEs are usually more trouble than they're worth. 32-bit applications have access to more features and are usually a little faster than 64-bit applications, so that's the default. The beta versions had a bug that defaulted all projects to x86, but the newest versions default class libraries to Any CPU. – Gerald Dec 01 '11 at 00:48

2 Answers2

20

You just need to add a configuration for Any CPU in the configuration manager.

1) Right-click the solution and select Properties

2) Select Configuration Properties, then click Configuration Manager...

3) Change the Active Solution platform to Any CPU. If there is no Any CPU platform, skip to #4.

4) Click the arrow in the combo box under the Platform column for your class library, and select New...

5) Make sure "Any CPU" is selected under New Platform. If there was no Any CPU solution platform in step 3, then make sure the "Create new solutions platform" checkbox is checked. Then click OK.

6) Check the checkbox in the "Build" column for your class library

7) Close out of the Configuration Manager, and open the properties for your class library

8) Select Any CPU for Platform, then select Any CPU for Platform target, and save.

(Step 8 may or may not be necessary, depending on what has been done with the configurations previously.)

Gerald
  • 23,011
  • 10
  • 73
  • 102
  • 2
    Do you know of a way to do this by default for all new console programs? – naasking Jan 06 '12 at 02:25
  • 8
    I can't create `AnyCPU` because I get error that this configuration already exists, but I can't select it for console app. – Johnny_D May 12 '14 at 09:21
  • 2
    @Johnny_D unchecking the "Create new solutions platform" check box worked for me. – James Esh Jan 12 '17 at 16:28
  • 1
    @Gerald, i wanted to have x64, at Step 4, i don't see 'new' item in combo box menu (under platform column) hence unable to build for 64bit. any workarounds? – Prakash M Apr 01 '17 at 07:13
  • 1
    I had the same problem with [EmguCV](https://excellmedia.dl.sourceforge.net/project/emgucv/emgucv/3.1.0-r16.12/libemgucv-windesktop-3.1.0.2504-r16.12.exe) in visual studio 2015 community edition there are two projects Emgu.CV.UI and Emgu.CV.World . for UI there is 'new' option, but its missing for World – Suraksha Ajith Apr 01 '17 at 07:24
-1

Just add a configuration for Any CPU in the configuration manager.

  1. Right-click the solution and select Properties.

  2. Select Configuration Properties, then click Configuration Manager.

  3. Change the Active Solution platform to Any CPU. If there is no Any CPU platform, go ahead to step 4.

  4. Click the arrow in the combo box under the Platform column for your class library, and select New.

  5. Make sure Any CPU is selected under New Platform. If there was no Any CPU solution platform in step 3, then make sure the "Create new solutions platform" checkbox is checked. Then click OK.

  6. Check the checkbox in the "Build" column for your class library

  7. Close out of the Configuration Manager, and open the properties for your class library

  8. Select Any CPU for Platform, then select Any CPU for Platform target, and save.

Step 8 may or may not be necessary, depending on what has been done with the configurations previously.

Noel Widmer
  • 4,444
  • 9
  • 45
  • 69
Anathi
  • 1