Windows Phone 8 个应用中的配置特定变量值
Configuration Specific Variable Values in Windows Phone 8 Apps
我想做的是根据当前配置设置不同的变量值。因此,当我 运行 Debug 中的项目时,我希望该应用程序指向我的开发堆栈。当我 运行 Release 中的应用程序时,我希望该应用程序针对我的生产堆栈 运行。我想创建一个 Beta 配置,它与我的 Release 配置设置基本相同,但略有不同。
谢谢!
查看 Visual Studio 的 Slow Cheetah 扩展。它允许您根据当前构建配置转换配置文件。
或者您可以使用 Conditional Compilation Symbols。但我推荐配置转换。
编辑:
鉴于您无法使用配置转换,我认为您不得不走编译符号路线。所以我会创建配置文件,然后 class 使用编译符号在运行时读取正确的文件。大致如下:
public class ConfigurationLoader()
{
private readonly string _configFile;
public ConfigurationLoader()
{
#if DEBUG
_configFile = "app.Debug.config";
#else
_configFile = "app.Release.config";
#endif
}
public UniversalAppConfig LoadCofig()
{
// Read file
// Create UniversalAppConfig
}
}
public class UniversalAppConfig()
{
public int ConfigurationValueA { get; set; }
public int ConfigurationValueB { get; set; }
}
顺便在Project Properties -> Build下设置符号。
我想做的是根据当前配置设置不同的变量值。因此,当我 运行 Debug 中的项目时,我希望该应用程序指向我的开发堆栈。当我 运行 Release 中的应用程序时,我希望该应用程序针对我的生产堆栈 运行。我想创建一个 Beta 配置,它与我的 Release 配置设置基本相同,但略有不同。
谢谢!
查看 Visual Studio 的 Slow Cheetah 扩展。它允许您根据当前构建配置转换配置文件。
或者您可以使用 Conditional Compilation Symbols。但我推荐配置转换。
编辑:
鉴于您无法使用配置转换,我认为您不得不走编译符号路线。所以我会创建配置文件,然后 class 使用编译符号在运行时读取正确的文件。大致如下:
public class ConfigurationLoader()
{
private readonly string _configFile;
public ConfigurationLoader()
{
#if DEBUG
_configFile = "app.Debug.config";
#else
_configFile = "app.Release.config";
#endif
}
public UniversalAppConfig LoadCofig()
{
// Read file
// Create UniversalAppConfig
}
}
public class UniversalAppConfig()
{
public int ConfigurationValueA { get; set; }
public int ConfigurationValueB { get; set; }
}
顺便在Project Properties -> Build下设置符号。