简体   繁体   中英

Passing command line argument as part of release build

I have a winform project. I would like to pass a command line argument as part of release build. ie MyProject.exe "BETA"

At the moment, I am passing this argument in the shortcut of the executable file. I am able to build this project with "BETA" as argument in debug build only. I am not able to do that in release build.

What I did was

  1. Open project properties
  2. Choose Debug Option
  3. Set "BETA" in command line arguments under the Start Options

I did the same for the release build. Unfortunately that argument is not available during runtime.

Any ideas?

regards, Alan

It is not possible to do this in runtime, user can run your program directly, not by shortcut. My suggestion is to use App.Config. You can have as many config files as you need: for debug, release, beta, alpha, testings and so on. App.Config can store parameters you need and can be modified externally and by your program too. MSDN , and look here

<configuration>
   <appSettings>
      <add key="BETA" value="True" />
   </appSettings>
</configuration>

My second suggestion is to use preprocessor directives and define beta mode in compile time. More links: link 1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM