编辑XML文档CSProj [英] Edit XML Document CSProj

查看:47
本文介绍了编辑XML文档CSProj的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我必须在解决方案中更新csproj文件.我需要更改预构建事件节点的当前值

I have to update the csproj file in my solution.  I need to change the current value of the prebuild event node

到目前为止,我一直在尝试这种方法....但是它不正确,因为我一直在获取System.NullReferenceException

So far I've been attempting this.... however it's not correct, as I keep getting a System.NullReferenceException

有什么想法吗?

    

     

XmlDocumentxmldoc = newXmlDocument();

               xmldoc.Load(文件名);

                xmldoc.Load(filename);

               xmldoc.SelectSingleNode(

                xmldoc.SelectSingleNode(

).InnerText = ;

"/PropertyGroup/PreBuildEvent").InnerText = "New Value";

               xmldoc.Save(文件名);

                xmldoc.Save(filename);

 

推荐答案

Hello William255,

Hello William255,

我怀疑这是您的xpath查询未选择节点.  查询"/PropertyGroup/PreBuildEvent "将工作 如果文档如下所示:

I suspect it is your xpath query is not selecting the node.  The query "/PropertyGroup/PreBuildEvent" will work if the document looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
<PropertyGroup>
  <PreBuildEvent>Old Value</PreBuildEvent>
</PropertyGroup>

但是我怀疑该节点被埋得更深了.  如果您确信只有一个匹配项,则可以将查询更新为"//".开头表示匹配树中的任何PropertyGroup.

"//PropertyGroup/PreBuildEvent ""


这篇关于编辑XML文档CSProj的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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