替换msbuild变量中的字符 [英] Replace characters within an msbuild variable

查看:79
本文介绍了替换msbuild变量中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要替换要传递给msbuild 4中exec任务的变量中的字符.具体地说,我需要用$(MSBuildProjectDirectory)变量中的正斜杠/替换所有出现的反斜杠\.

I need to replace characters in a variable I am passing to an exec task within msbuild 4. Specifically, I need to replace all occurrences of backslashes \ with forward-slashes / in the $(MSBuildProjectDirectory) variable.

例如:

<Target Name="DoStuff">
    <Exec Command="stuff.exe $(MSBuildProjectDirectoryWithSlashesFixed)/SomeFile.txt" />
</Target>

被调用的可执行文件是一个oracle组件,无法处理Windows格式的斜杠.

The executable being called is an oracle component that can't deal with slashes in windows format.

我看过属性函数,但是System.String.Replace()是实例方法,而不是静态方法,看来它不能满足我的需求.

I've had a look at Property Functions, but as System.String.Replace() is an instance method rather than a static method, it seems it can't be used for my needs.

有什么想法吗?

推荐答案

您还可以将实例方法用作属性函数(只要您将自己限制为注册为安全的类型).

You can also use instance methods as property functions (as long as you restrict yourself to types registered as safe).

<PropertyGroup>
  <MSBuildProjectDirectoryWSF>$(MSBuildProjectDirectory.Replace('\', '/'))</MSBuildProjectDirectoryWSF>
</PropertyGroup>

(我可能已经错过了一些在斜杠上的转义).

(I might have missed some escaping on the slashes).

有关更多文档,请访问 Visual Studio博客.

More documentation is available on Visual Studio Blog.

这篇关于替换msbuild变量中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆