MSBuild - 将转义字符写入文件
我遇到的场景与这篇文章中描述的场景非常相似。它描述了如何加载包含属性和属性的文件的内容。项目,确保它们作为流程的一部分得到解决。我正在做同样的事情,除了将内容写入另一个文本文件(通常是 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了类似的情况,但只是在 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.