7

How can I pass a custom MsBuild property to Visual Studio build engine from Visual Studio Extension (I want to write a custom add-in) ? Just like Visual Studio itself is passing properties like $(Configuration) and $(Platform), I would like to attach to a build process and pass my own property (e.g. $(MyCustomProperty) = "foobar"). I know it can be accomplished using MsBuild command line (/p:Property), but I want to do it from an extension.

Here is an example of what I would like to accompilsh: a textbox on visual studio toolbar, where user can type in some text - a value, that I would like to pass to build engine.

Then in .csproj:

<PropertyGroup>
  <MyCustomProperty Condition=" '$(MyCustomProperty)' == '' ">DefaultValue</MyCustomProperty>
</PropertyGroup>

<Target Name="AfterBuild" Condition=" '$(MyCustomProperty)' = 'DoAfterBuild' ">
  ...
</Target>

So target AfterBuild would be exectued only if user typed DoAfterBuild into my extension's text box

4

1 回答 1

4

您可以请求服务IVsBuildPropertyStorage,它有以下方法:

SetPropertyValue:项目子类型用于设置 MSBuild 属性值。

像这样的东西:

EnvDTE.Project proj = ...;
var sol = Package.GetGlobalService(typeof(VsSolution)) as IVsSolution;
IVsHierarchy hier;
sol.GetProjectOfUniqueName(p.UniqueName, out hier);
var storage = hier as IVsBuildPropertyStorage;
storage.SetPropertyValue(..);
于 2014-08-14T17:20:34.893 回答