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? 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?
-
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?
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
-
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?
[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
-
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?
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.