对应用程序的调试和发布版本使用不同的 AppData 文件夹

Use different AppData folders for Debug and Release builds of an application

如果我有一个名为 MyApplication 的应用程序,是否可以为该应用程序的本地 AppData 目录设置一个自定义位置?例如:C:\Users\User1\AppData\Local\MyApplication2。我在任何地方都找不到如何更改它。

编辑

澄清:我不想创建一个名为 C:\Users\User1\AppData\Local\MyApplication2 的辅助目录。我希望系统将 C:\Users\User1\AppData\Local\MyApplication2 识别为 MyApplication.

的实际本地 AppData 目录

编辑 2:

我真的需要一种方法来在我的计算机上同时安装调试和发布版本,以便尽可能接近现实。到目前为止,我设法更改了应用程序的安装位置和其他应用程序级别的标识符,但我无法更改 AppData 以便每个人都使用不同的设置文件。

如果您只是想在计算机上开发代码时更改位置,则无需移动 {localappdata} 的位置。事实上,根本没有必要让 Inno Setup 参与其中。

只需根据编译器定义的值在您的代码中定义一个局部变量(例如 #IFDEF DEBUG)。在安装期间创建 %LOCALAPPDATA%\MyApplication2 文件夹。定义 DEBUG 后,在运行时(这将在开发期间)附加到该位置到 read/write 来自 Debug 文件夹的配置信息。

我不知道你用什么语言编写代码,但在 Delphi 中它会是这样的:

{$IFDEF DEBUG}
const
  ConfigDir = 'Debug\';
{$ENDIF}

// At application startup, retrieve the contents of %LOCALAPPDATA% via API call
// or by retrieving the contents of the environmental variable (say into the
// DataDir variable). Then...
{$IFDEF DEBUG}
DataDir := DataDir + ConfigDir;
// If needed, you can check here for whether the folder exists and
// create it if it doesn't.
{$ENDIF}

现在您访问配置信息的所有代码都只是从 DataDir 中检索它,这将根据您是处于调试模式还是发布模式进行调整。