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.

Jay Bazuzi
  • 45,157
  • 15
  • 111
  • 168
José F. Romaniello
  • 13,866
  • 3
  • 36
  • 38
  • Are you certain that MSBuild won't accept the escaped forms of those characters? – Jay Bazuzi Oct 25 '10 at 06:15
  • 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. – José F. Romaniello Oct 28 '10 at 02:30

1 Answers1

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

Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
  • 1
    The documentation is not correct (not your fault). You are actually looking for the [`IVsBuildPropertyStorage2`](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildpropertystorage2.aspx) interface, which added the [`SetPropertyValueEx`](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivsbuildpropertystorage2.setpropertyvalueex.aspx) method starting in Visual Studio 2010. – Sam Harwell Aug 14 '14 at 18:00
  • Ah thanks, I knew something fishy was going on, though, I noticed that this is SetPropertyValue, not SetItemAttribute. Not sure if that helps. – Erti-Chris Eelmaa Aug 14 '14 at 18:06
  • 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 :) – José F. Romaniello Aug 14 '14 at 18:44
  • @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`. – reduckted Jun 19 '17 at 05:16