【问题标题】:How do I prevent IVsBuildPropertyStorage.SetItemAttribute from escaping special characters?如何防止 IVsBuildPropertyStorage.SetItemAttribute 转义特殊字符?
【发布时间】:2010-10-24 12:39:44
【问题描述】:

我正在开发 Visual Studio 2010 扩展,我想向 MSBuild 项添加一个属性,如下所示:

 <EmbeddedResource Include="SomeFile.xml">
      <FooAttribute>%(Filename)%(Extension)</FooAttribute>
 </EmbeddedResource>

所以,到目前为止,我发现的唯一方法是使用方法 IVsBuildPropertyStorage.SetItemAttribute 。这适用于简单的字符串,但是当我尝试使用 MSBuild 特有的字符时,我得到了这个结果:

 <EmbeddedResource Include="SomeFile.xml">
      <FooAttribute>%29%25%28Filename%29%25%28Extension%29</FooAttribute>
 </EmbeddedResource>

这意味着 SetItemAttribute 会自动从 MsBuild 字符中转义,我不希望这样。

【问题讨论】:

  • 您确定 MSBuild 不会接受这些字符的转义形式吗?
  • 它接受那些字符的转义形式...但我不想转义我想在我的项目文件中使用“%(Filename)%(Extension)”。如果我让 "%29%25%28Filename%29%25%28Extension%29" msbuild 会把它当作一个字符串常量。

标签: c# visual-studio-2010 msbuild envdte vsix


【解决方案1】:

这个问题有点老了,但需要一个答案。 VS2010似乎有更好的界面,可以设置值而不转义。

IVsBuildPropertyStorage2 接口

由项目系统实现,让风味访问 MSBuild 属性系统。这个接口提供了更多的灵活性 围绕设置属性而不是 IVsBuildPropertyStorage。它允许 添加一个新的条件属性组并且 不会转义 值。

即函数SetPropertyValueExhttp://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildpropertystorage2.setpropertyvalueex.aspx

【讨论】:

  • 文档不正确(不是你的错)。您实际上是在寻找 IVsBuildPropertyStorage2 接口,它从 Visual Studio 2010 开始添加了 SetPropertyValueEx 方法。
  • 啊,谢谢,我知道发生了一些可疑的事情,但是,我注意到这是 SetPropertyValue,而不是 SetItemAttribute。不确定这是否有帮助。
  • 老实说,它太老了,我完全忘记了我在做什么,我不再在.Net土地上。但迟到总比没有好:)
  • @SamHarwell 你如何获得IVsBuildPropertyStorage2?我可以将IHierarchy 转换为IVsBuildPropertyStorage,但我不能将它转换为IVsBuildPropertyStorage2
猜你喜欢
  • 1970-01-01
  • 2014-03-15
  • 2012-09-18
  • 2015-01-01
  • 2017-05-02
  • 1970-01-01
  • 2012-04-14
  • 2016-06-11
  • 2019-06-21
相关资源
最近更新 更多