用于查找和查找的 .NET 正则表达式在 C# 中替换 .vdproj 文件中的任何 ProductName 值
我正在尝试编写一个 NAnt 扩展任务,该任务可以更新 Visual Studio 2003 生成的安装程序 .vdproj 文件中的不同设置,并且希望获得以下方面的帮助。
具体来说,我想使用 RegEx 表达式来查找,如果找到,则将分配给 ProductName 值的任何值字符串值替换为新的字符串值。
我正在寻找一个正则表达式集,用于将“ProductName”更改为任何其他值,而无需依赖于所查找的字符串以“ProductName”=“8”开头:然后有 1 个或多个字符并以 a 结尾的任何其他值” 标记。我尝试了以下方法,但没有效果:
在执行以下代码片段之前,.vdproj 文件的 ProductName 为:
"ProductName" = "8:My Simple .NET Application"
... 以及 C# 中的代码片段:
string _theProductName = "My Other Native Application";
Regex productNameExpression = new Regex( @"(?:\""ProductName\"" = \""8:*)" );
_theProjectFileContents =
productNameExpression.Replace(_theProjectFileContents,
"\"ProductName\" = \"8:" + _theProductName + "\"" );
bool updatedProductName =
(_theProjectFileContents.IndexOf(_theProductName) >= 0);
执行上述代码片段后,.vdproj 文件的 ProductName 现在为阅读:
"ProductName" = "8:My Simple .NET Application"My Other Native Application"
关闭,但我期望“我的其他本机应用程序”取代“我的简单.NET应用程序”,并且不添加
任何见解和帮助将不胜感激。
I'm trying to write a NAnt extension task that can update different settings within a Visual Studio 2003 generated Setup .vdproj file, and would appreciate help with the following.
Specifically, I would like to use a RegEx expression to find, and if found, replace any value string value assigned to the ProductName value with a new string value in its entirty.
I am looking for a RegEx expression set to change "ProductName" to any other value without having to rely on anything other than that the string sought begins with "ProductName" = "8": and then has 1 or more characters and ends with a " mark. I've tried the following to no avail:
Before executing the following code fragment, the .vdproj file's ProductName reads:
"ProductName" = "8:My Simple .NET Application"
... and the code fragment in C#:
string _theProductName = "My Other Native Application";
Regex productNameExpression = new Regex( @"(?:\""ProductName\"" = \""8:*)" );
_theProjectFileContents =
productNameExpression.Replace(_theProjectFileContents,
"\"ProductName\" = \"8:" + _theProductName + "\"" );
bool updatedProductName =
(_theProjectFileContents.IndexOf(_theProductName) >= 0);
After executing the above code fragment, the .vdproj file's ProductName now reads:
"ProductName" = "8:My Simple .NET Application"My Other Native Application"
Close, but I was expecting "My Other Native Application" to replace "My Simple .NET Application", and not add to it.
Any insights and help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经非常接近了 - 只缺少一个 。
因此改变你的正则表达式,幸福就会随之而来......
注意 . 8之后:
You're very nearly there - only missing a single .
Change your regex thus and happiness should follow...
Note the . after the 8: