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. How to make code run differently depending on the platform it is running on?

How to make code run differently depending on the platform it is running on?

Scheduled Pinned Locked Moved C#
csharpasp-netvisual-studiosysadminhelp
4 Posts 4 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.
  • X Offline
    X Offline
    Xarzu
    wrote on last edited by
    #1

    How to make code run differently depending on the platform it is running on? I have a challenge for you. I have an ASP.NET Web Application built in C# with Microsoft Visual Studio 2017. There is a line of code that we have had to include in order for it to run on a localhost when debugging by attaching it to a running process in a web browser. Here is the issue. That line of code is not necessary when the process is running on the server. I can remove that line when I submit the code in TFS. But it would be great if we could make the code somehow ignore that line depending on what platform it is running on. How can you think this could be done?

    Richard DeemingR L J 3 Replies Last reply
    0
    • X Xarzu

      How to make code run differently depending on the platform it is running on? I have a challenge for you. I have an ASP.NET Web Application built in C# with Microsoft Visual Studio 2017. There is a line of code that we have had to include in order for it to run on a localhost when debugging by attaching it to a running process in a web browser. Here is the issue. That line of code is not necessary when the process is running on the server. I can remove that line when I submit the code in TFS. But it would be great if we could make the code somehow ignore that line depending on what platform it is running on. How can you think this could be done?

      Richard DeemingR Offline
      Richard DeemingR Offline
      Richard Deeming
      wrote on last edited by
      #2

      Use a preprocessor directive to only include the line of code in a specific build: #if preprocessor directive - C# Reference | Microsoft Docs[^] Have a different build configuration will also let you use config file transforms to tweak your web.config for each platform: ASP.NET Web Deployment using Visual Studio: Web.config File Transformations | Microsoft Docs[^]


      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

      1 Reply Last reply
      0
      • X Xarzu

        How to make code run differently depending on the platform it is running on? I have a challenge for you. I have an ASP.NET Web Application built in C# with Microsoft Visual Studio 2017. There is a line of code that we have had to include in order for it to run on a localhost when debugging by attaching it to a running process in a web browser. Here is the issue. That line of code is not necessary when the process is running on the server. I can remove that line when I submit the code in TFS. But it would be great if we could make the code somehow ignore that line depending on what platform it is running on. How can you think this could be done?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        [How to add parameter to Web.Config and how to retrieve the value? | The ASP.NET Forums](https://forums.asp.net/t/1250916.aspx?How+to+add+parameter+to+Web+Config+and+how+to+retrieve+the+value+)

        "(I) am amazed to see myself here rather than there ... now rather than then". ― Blaise Pascal

        1 Reply Last reply
        0
        • X Xarzu

          How to make code run differently depending on the platform it is running on? I have a challenge for you. I have an ASP.NET Web Application built in C# with Microsoft Visual Studio 2017. There is a line of code that we have had to include in order for it to run on a localhost when debugging by attaching it to a running process in a web browser. Here is the issue. That line of code is not necessary when the process is running on the server. I can remove that line when I submit the code in TFS. But it would be great if we could make the code somehow ignore that line depending on what platform it is running on. How can you think this could be done?

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          I would question why that line is needed at all. Perhaps your real problem is figuring out what process to attach to when you want to debug. If so you can log the process id. That provides all that you need. Other than that there is a problem with running code one way on some machines and then running it differently in production. That is because you are not then testing the code that runs in production. Consequently problems can occur in production for which you have no way to replicate exception in production.

          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