views:

1359

answers:

3

I am working on some C# projects with Visual Studio 2005, and I am trying to change the platform target from x86 to Any CPU. I already went through all the dependencies that I know about and made sure that they were also built for Any CPU using the corflags tool.

When I change the platform target in Visual Studio 2005 it seems like it saves the change, but then when I build the project it still uses x86 anyway. The next time I open the project the platform target has been reset to x86.

This only happens for a couple of the projects in the solution, does this mean that there are other 32-bit dependencies somewhere?

I can manually run the C# compiler on the command line with /platform:anycpu and I don't get an error, but I'm not sure that is the right thing to do and I'd like to be able to build within Visual Studio.

What can I do to solve this problem?

A: 

You will not be able to do this for a managed project and I think that setting is irrelevant to managed projects as they should run on any cpu really.

gyurisc
What do you mean by "managed project"? From what I understand I should be able to build my assemblies as either x86, x64, or anycpu, by changing the platform target setting in the build properties.
bde
-1, the setting is relevant for Managed Projects if they use Unmanaged DLLs.
sixlettervariables
I did not think of x86 or x64 I thought only pure managed code
gyurisc
+3  A: 

Make sure you've changed both the Configuration Platform and the Platform Target to Any CPU. If all else fails you can open up the .csproj and manually change the references. Right click on the Project, goto Unload Project. Then right click and goto Edit MyProject.csproj. The properties for the project may still include the default Platform as x86:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>

Also consider the case where the Solution still has the x86 configuration in Configuration Manager. I've found for some complex Solutions with multiple projects that have different configurations I have to spend a lot of time in Configuration Manager getting everything straight.

sixlettervariables
I had changed both the Configuration Platform and Platform Target, and it still wouldn't save the change. I was able to edit the .csproj file and do it that way, so I think this is what I was looking for at this point. Whether or not it actually runs is another story. I still get the feeling that this might have to do with dependencies that I can't see being targeted for other platforms, but it's hard to say.
bde
+1  A: 

I agree with AskAboutGadgets.com, this doesn't seem a relevant option.

As with Java bytecode, a .NET compiled CLI binary is identical on x86, PPC or SPARC (I've run the same CLI binaries on all three, under Windows, Mac OS, Linux and Solaris - which I've created using both Mono and Visual Studio).

I can't think of any reason to want to set the target to a specific architecture, or how this option would theoricially changed the resulting CLI bytecode (Some meta data perhaps? Does it impact other aspect of the build process in some way, like impacting the dependancies enforced by an installer?).

If you don't have a specific concern I think it's safe to say you can ignore this option, although if it's created with Visual Studio it's likely, though admittedly not necessarily, the case that the resulting CLI binary has some Microsoft .NET specific dependancies in order to function correctly (and so would be limited to Microsoft Windows on x86 in any case).

If anyone can explain what difference this would have in Visual Studio I'd appreciate an explanation.

Iain Collins
If your .Net project is going to run on x64 and uses x86 DLLs, then you MUST compile as x86. This way the executable runs on WOW64 and then can use 32bit DLLs.
sixlettervariables
@sixlettervariables Oh, interesting I see ... that point to be covered on SO too. I hadn't come across this issue (currently we have no problems on x64, touch wood), but I'm sure it will come up at some point, thanks.
Iain Collins
sometimes those x86 DLLs are not even directly referenced by your project, in the case of a certain ODBC driver I was using, the binary compile targeting x86 or it couldn't find the ODBC driver