Visual Studio c#调试和发布的文件内容不同

tquggr8v  于 2023-01-17  发布在  C#
关注(0)|答案(1)|浏览(237)

我有.txt文件,我希望其内容的某些部分在调试和发布版本中有所不同。

{Bunch of text. debug and release...}

#if DEBUG
{My texts onlyfor debug build}
#else
{And texts onlyfor release}
#endif

{Other bunch of texts...}

这可能吗?

yrefmtwq

yrefmtwq1#

您可以根据示例使用#if DEBUG语句在应用程序启动时生成.txt文件。
你甚至可以包含两个文件myFile.txt.debug和myFile.txt.release,然后在应用程序启动时将正确的文件复制到myFile.txt中,这些文件可以作为内容文件或包含在项目资源中。
对于XML和JSON文件,您可以使用https://github.com/microsoft/slow-cheetah根据构建配置生成文件。

相关问题