MSBuild - 将转义字符写入文件

发布于 2024-08-19 11:45:46 字数 935 浏览 2 评论 0原文

我遇到的场景与这篇文章中描述的场景非常相似。它描述了如何加载包含属性和属性的文件的内容。项目,确保它们作为流程的一部分得到解决。我正在做同样的事情,除了将内容写入另一个文本文件(通常是 .ini 文件)。

简而言之,我首先导入包含以下文本的项目/属性组:

; -----------

[标题]

设置1=$(第一个值)

设置2=$(SecondValue)

setting3=列表;of;值;分隔;分号

setting4=bla bla bla

; -----------

&希望将其写入包含以下内容的新 .ini 文件:

; -----------

[标题]

setting1=由 msbuild 解析的值

setting2=msbuild 解析的另一个值

setting3=列表;of;值;分隔;分号

setting4=bla bla bla

; -----------

唯一的问题是某些文件将包含分号。我可以在没有注释的情况下生活,但它们也被用作值的一部分,例如在列表中。这是使用 WriteLinesToFile 任务的结果。分号被视为转义字符 &会产生新行,因此上例中“setting3”的值将分为 6 行。

有没有办法解决这个问题而不执行我自己的任务?

预先感谢您的帮助!

I've got a very similar scenario to the one described in this post. It describes how to load the contents of a file that contains properties & items, making sure they're resolved as part of the process. I'm doing the same thing except writing the contents away to another text file (generally .ini file).

In short I'd start by importing a project / propertygroup which contains this text:

; -----------

[heading]

setting1=$(FirstValue)

setting2=$(SecondValue)

setting3=list;of;values;delimited;by;semicolons

setting4=bla bla bla

; -----------

& hopefully write it away to a new .ini file containing the following:

; -----------

[heading]

setting1=value resolved by msbuild

setting2=another value resolved by msbuild

setting3=list;of;values;delimited;by;semicolons

setting4=bla bla bla

; -----------

Only problem is that some files will contain semicolons. I can live without comments, but they're also used as part of values e.g. in lists. This is the result of using the WriteLinesToFile task. The semicolons are treated as escape characters & result in new lines, so the value of 'setting3' in the above example would be split over 6 lines.

Is there a way around this without implementing my own task?

Thanks in advance for the help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妥活 2024-08-26 11:45:46

我遇到了类似的情况,但只是在 WriteLinesToFile 任务中使用包含分号的静态文本。我通过使用 %3B 作为分号的转义字符来使其工作。

如果您可以让分号在内存值中正确显示(使用消息任务来检查这一点),那么您可能只需将它们替换为 %3B 即可将文件写出。

I had a similar situation but just using static text containing semi-colons in the WriteLinesToFile task. I got it to work by using %3B as an escape character for semi-colon.

If you can get the semi-colons to show up properly in the in-memory value (use the Message task to check this) then you may just need to replace them with %3B to write the file out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文