简体   繁体   中英

How do I determine the web origin folder of a ClickOnce application?

I have an C# application that is deployed as a ClickOnce application. The installation files can live in one of three possible folders on our web server: Alpha, Beta, and Production. The user addresses the appropriate location in IE to start the application: www.foo.com/Alpha, www.foo.com/Beta, or www.foo.com/Prod. In testing, we copy the installation files to Alpha first, then (when it passes testing) to Beta, then (when it passes user acceptance), to production. There is no recompilation.

What I want to know is whether there is any way the C# code can know at runtime which version it is: Alpha, Beta, or Production. It would be based only on which folder the ClickOnce installation files were located in. Remember that there has been no recompilation.

Any clues?

Thanks!

You could do this with a custom manifest element, but it will require some post-build processing.

The application can access the manifest file simply by opening a file stream on the AppName.exe.manifest file, and parsing the XML to locate and read the custom element. The manifest is deployed to the same directory as the executable.

When the application files are copied to a web server folder, simply modify the manifest to append the custom element (it could technically even be an XML comment, parsed with simple text comparison, if you don't want to use an XML parser).

After the manifest is modified (in each folder), it will have to be re-signed with the mage.exe signing tool.

You can automate this with a shell script fairly easily. On the whole, however, it would probably be a lot simpler to just build different actual versions.

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