How do I prevent IVsBuildPropertyStorage.SetItemAttribute from escaping special characters?
Asked Answered
S

1

6

I am working on a Visual Studio 2010 extension and I want to add an attribute to an MSBuild Item, as follows:

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

So, far the only way I found is using the method IVsBuildPropertyStorage.SetItemAttribute . This works fine for simple strings, but when i try to use characters that are special to MSBuild, I get this result:

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

This means that SetItemAttribute automatically escapes from MsBuild characters and I don't want that.

Synovitis answered 24/10, 2010 at 12:39 Comment(2)
Are you certain that MSBuild won't accept the escaped forms of those characters?Cruzcruzado
It accept escaped form for those characters... BUT i don't want to escape i want "%(Filename)%(Extension)" in my project file. If i let "%29%25%28Filename%29%25%28Extension%29" msbuild will take this like as a string constant.Armalda
U
2

This question is a bit old, but needs an answer. VS2010 seems to have better interface that can set values without escaping.

IVsBuildPropertyStorage2 Interface

Implemented by the project system to give flavors access to the MSBuild property system. This interface provides more flexibility around setting properties than IVsBuildPropertyStorage. It allows for adding a new conditional property group and does not escape the values.

Namely the function SetPropertyValueEx: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildpropertystorage2.setpropertyvalueex.aspx

Unblock answered 14/8, 2014 at 17:30 Comment(4)
The documentation is not correct (not your fault). You are actually looking for the IVsBuildPropertyStorage2 interface, which added the SetPropertyValueEx method starting in Visual Studio 2010.Shogun
Ah thanks, I knew something fishy was going on, though, I noticed that this is SetPropertyValue, not SetItemAttribute. Not sure if that helps.Unblock
To be honest, it is so old that I completely forgot what I was doing, I'm no longer in .Net land. But better later than never :)Armalda
@SamHarwell How do you actually get an IVsBuildPropertyStorage2? I can cast an IHierarchy to an IVsBuildPropertyStorage, but I can't cast it to an IVsBuildPropertyStorage2.Ralston

© 2022 - 2024 — McMap. All rights reserved.