Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Display Target Platform

Display Target Platform

Scheduled Pinned Locked Moved C#
csharpvisual-studioalgorithmstestingbeta-testing
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnneThorne
    wrote on last edited by
    #1

    Hi, I have done some searching for this and have not found exactly what I need. I have created a Windows Application in C#, Dot Net Framework 2, for my company. It currently has a Target Platform of "any cpu". The company is slowly migrating to use 64 bit machines. Also we would like to upgrade the Windows Application to Dot Net Framework 4. Management wants to be sure that changing to an x86 target platform (this is the target platform that needs to be used for both x32 and x64 bit machines to run the application) and changing to Dot Net Framework 4, will not break anything. So: For testing, I want to create 2 applications with the same source code. 1) (Using Visual Studio 2005 to build and publish): Current Visual Studio settings: Dot Net Framework 2, and Target Platform: any cpu 2) (Using Visual Studio 2010 to build and publish): Dot Net Framework 4, and Target Platform: x86 In a label on the application, I want to display the Dot Net Version (I know how to do that). Then I also want to display the Target Platform, which will either be : "any cpu" or "x86". After searching the internet for about 15 minutes, I discovered how to differentiate between, x32 and x64; or perhaps between x32 and x86... This is by simply using the IntPtr.Size property. But.. How would I differentiate between "any cpu" and x86. Or what if I wanted to differentiate between x86 and x64? Thanks in advance for any advice anyone can give me with this. :) Anne

    J A B 3 Replies Last reply
    0
    • A AnneThorne

      Hi, I have done some searching for this and have not found exactly what I need. I have created a Windows Application in C#, Dot Net Framework 2, for my company. It currently has a Target Platform of "any cpu". The company is slowly migrating to use 64 bit machines. Also we would like to upgrade the Windows Application to Dot Net Framework 4. Management wants to be sure that changing to an x86 target platform (this is the target platform that needs to be used for both x32 and x64 bit machines to run the application) and changing to Dot Net Framework 4, will not break anything. So: For testing, I want to create 2 applications with the same source code. 1) (Using Visual Studio 2005 to build and publish): Current Visual Studio settings: Dot Net Framework 2, and Target Platform: any cpu 2) (Using Visual Studio 2010 to build and publish): Dot Net Framework 4, and Target Platform: x86 In a label on the application, I want to display the Dot Net Version (I know how to do that). Then I also want to display the Target Platform, which will either be : "any cpu" or "x86". After searching the internet for about 15 minutes, I discovered how to differentiate between, x32 and x64; or perhaps between x32 and x86... This is by simply using the IntPtr.Size property. But.. How would I differentiate between "any cpu" and x86. Or what if I wanted to differentiate between x86 and x64? Thanks in advance for any advice anyone can give me with this. :) Anne

      J Offline
      J Offline
      Jeremy Hutchinson
      wrote on last edited by
      #2

      The whole idea of the 'Any CPU' setting is that it runs on both x86 (32 bit) and x64 (64 bit). Unless you're running into a specific problem that can be resolved by selecting x86 or x64, you should probably leave that setting on Any CPU. Now to answer your actual question: If you build x86, you will then IntPtr.Size will be 4. If you build x64 IntPtr.Size will be 8. If you build Any CPU, IntPtr.Size will be 4 on 32 bit windows and 8 on 64 bit windows. So that won't help identify the Any CPU compiler setting. So, you would need to create 3 project files (2 copies of the original), then add a Conditional Compilation Symbol in each of the project files. Then set the Label's text based on those symbols.

      string platformTarget = "unknown";
      #if x86
      platformTarget = "x86";
      #elif x64
      platformTarget = "x64";
      #elif AnyCPU
      platformTarget = "AnyCPU";
      #endif
      lblPlatformTarget = platformTarget;

      You can do something similar with comparing Framework 2 and 4. The upgrade from 2 to 4 should be completely painless.

      My Blog[^] Chess Tactics for WP7[^]

      1 Reply Last reply
      0
      • A AnneThorne

        Hi, I have done some searching for this and have not found exactly what I need. I have created a Windows Application in C#, Dot Net Framework 2, for my company. It currently has a Target Platform of "any cpu". The company is slowly migrating to use 64 bit machines. Also we would like to upgrade the Windows Application to Dot Net Framework 4. Management wants to be sure that changing to an x86 target platform (this is the target platform that needs to be used for both x32 and x64 bit machines to run the application) and changing to Dot Net Framework 4, will not break anything. So: For testing, I want to create 2 applications with the same source code. 1) (Using Visual Studio 2005 to build and publish): Current Visual Studio settings: Dot Net Framework 2, and Target Platform: any cpu 2) (Using Visual Studio 2010 to build and publish): Dot Net Framework 4, and Target Platform: x86 In a label on the application, I want to display the Dot Net Version (I know how to do that). Then I also want to display the Target Platform, which will either be : "any cpu" or "x86". After searching the internet for about 15 minutes, I discovered how to differentiate between, x32 and x64; or perhaps between x32 and x86... This is by simply using the IntPtr.Size property. But.. How would I differentiate between "any cpu" and x86. Or what if I wanted to differentiate between x86 and x64? Thanks in advance for any advice anyone can give me with this. :) Anne

        A Offline
        A Offline
        Apocalypse Now
        wrote on last edited by
        #3

        any cpu:32 bit machine x86: 32bit or 64 bit machine x64: 64 bit machine

        L 1 Reply Last reply
        0
        • A AnneThorne

          Hi, I have done some searching for this and have not found exactly what I need. I have created a Windows Application in C#, Dot Net Framework 2, for my company. It currently has a Target Platform of "any cpu". The company is slowly migrating to use 64 bit machines. Also we would like to upgrade the Windows Application to Dot Net Framework 4. Management wants to be sure that changing to an x86 target platform (this is the target platform that needs to be used for both x32 and x64 bit machines to run the application) and changing to Dot Net Framework 4, will not break anything. So: For testing, I want to create 2 applications with the same source code. 1) (Using Visual Studio 2005 to build and publish): Current Visual Studio settings: Dot Net Framework 2, and Target Platform: any cpu 2) (Using Visual Studio 2010 to build and publish): Dot Net Framework 4, and Target Platform: x86 In a label on the application, I want to display the Dot Net Version (I know how to do that). Then I also want to display the Target Platform, which will either be : "any cpu" or "x86". After searching the internet for about 15 minutes, I discovered how to differentiate between, x32 and x64; or perhaps between x32 and x86... This is by simply using the IntPtr.Size property. But.. How would I differentiate between "any cpu" and x86. Or what if I wanted to differentiate between x86 and x64? Thanks in advance for any advice anyone can give me with this. :) Anne

          B Offline
          B Offline
          Bernhard Hiller
          wrote on last edited by
          #4

          Apart from the application, you should also test your development environment: developing 32bit applications with VisualStudio 2010 on a Windows 7 (64bit) computer may require some strange settings - it was hard to get it working correctly in our case. Therefore, test also that point.

          1 Reply Last reply
          0
          • A Apocalypse Now

            any cpu:32 bit machine x86: 32bit or 64 bit machine x64: 64 bit machine

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            don't think so. :|

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            A 1 Reply Last reply
            0
            • L Luc Pattyn

              don't think so. :|

              Luc Pattyn [My Articles] Nil Volentibus Arduum

              A Offline
              A Offline
              Apocalypse Now
              wrote on last edited by
              #6

              x86 could run in x64 platform and x32 platform. I used.

              L 1 Reply Last reply
              0
              • A Apocalypse Now

                x86 could run in x64 platform and x32 platform. I used.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #7

                any cpu: 32 bit machine code runs in 64-bit mode on Win64, in 32-bit mode otherwise (i.e. Windows decides based on Win itself and CPU) x86: 32bit or 64 bit machine code runs in 32-bit mode (or not at all when future x64 CPUs no longer support x86) x64: code runs in 64-bit mode on x64 CPUs and Win64, or not at all. For all of them, the process needs to be homogeneous; if parts (referenced DLLs) contain native code of the other persuasion, the app won't load. :)

                Luc Pattyn [My Articles] Nil Volentibus Arduum

                A 1 Reply Last reply
                0
                • L Luc Pattyn

                  any cpu: 32 bit machine code runs in 64-bit mode on Win64, in 32-bit mode otherwise (i.e. Windows decides based on Win itself and CPU) x86: 32bit or 64 bit machine code runs in 32-bit mode (or not at all when future x64 CPUs no longer support x86) x64: code runs in 64-bit mode on x64 CPUs and Win64, or not at all. For all of them, the process needs to be homogeneous; if parts (referenced DLLs) contain native code of the other persuasion, the app won't load. :)

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  A Offline
                  A Offline
                  Apocalypse Now
                  wrote on last edited by
                  #8

                  I see. Thank you very much. :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups