问题
I need to have three different build variants (flavors) of my UWP app that can be installed parallel: one for production, one for testing and one for development. They obviously need to share the same code base but have different constants like backend URLs and API keys.
In Android Studio this can be done using "build variants" and in Xcode this can be done using "schemes". What's the Visual Studio equivalent of those?
Maybe "build configurations" using the Configuration Manager as in https://msdn.microsoft.com/en-us/library/kwybya3w.aspx is the way to go. By default I have a Debug and a Release configuration. Would it be correct to rename those to Production-Debug and Production-Release and then create Testing-Debug, Testing-Release, Development-Debug and Development-Release? What I don't understand though:
- Will that allow me to install Production, Testing and Development parallel on the same device?
- How do I know which flavor I'm running in code (in order to get different properties, constants)?
EDIT: This is about UWP apps, not about web apps.
回答1:
You can just use conditionals like this:
<AppxManifest Include="Manifest.Debug.xml"
Condition="'$(Configuration)'=='Debug'">
<SubType>Designer</SubType>
</AppxManifest>
<AppxManifest Include="Package.appxmanifest"
Condition="'$(Configuration)'=='Release'">
<SubType>Designer</SubType>
</AppxManifest>
回答2:
Double click on Package.appxmanifest file in your project.
Select Packaging label and enter different Package names for different cases.
Store each of variants.
Your PC gonna think these are different UWP apps.
回答3:
I've found a solution using this guide: http://grogansoft.com/blog/?p=1087
I basically ended up having an appxmanifest (renamed to appxmanifest2 since you can only have one appxmanifest per project) per build configuration and then in the build events "pre-build event command line" I'm copying the one I need into the project root.
For the constants I'm using pre-processor conditional compilation symbols.
来源:https://stackoverflow.com/questions/40927615/uwp-visual-studio-how-to-make-different-builds-variants