Search code examples
c#visual-studiomsbuildvstobuild-process

creating a collection variable in MSBuild .targets


Context

An annoying Excel add-in compilation bug exists and the only way I am currently able to work around it is by editing the VSTO MSBuild .targets file

  • C:\Program Files\MSBuild\Microsoft\VisualStudio\v11.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets

With the modification below I am able to compile the Excel add-in, but with the side-effect that my custom ribbon is not shown any more.

The VSTO bug and workaround are described in detail here : "FindRibbons" task failed unexpectedly

.targets Modification with Undesired Side-Effect of Empty RibbonTypes

<!--  This part is causing the compilation to fail and has to be commented out -->
<!--  <FindRibbons-->
<!--           AssemblyName="$(AbsolutePathToCustomization)"-->
<!--           TargetFramework="$(TargetFrameworkVersion)"-->
<!--        >-->
<!--  <Output TaskParameter="RibbonTypes" ItemName="RibbonTypesCollection"/>-->
<!--  </FindRibbons>-->


<!-- Now RibbonTypes is empty, causing the side-effect-->       
<!-- Used to be RibbonTypes="@(RibbonTypesCollection)"-->       
<!-- Can I manually recreate @(RibbonTypesCollection)?-->       
<GenerateOfficeDocumentManifest Condition="'$(VSTO_ProjectType)' == 'Document'"
    SolutionID="$(SolutionID)"
    RibbonTypes=""
    TargetFramework="$(TargetFrameworkVersion)"
>

Filling the parameter manually?

Now I need to provide something like the following

"ProjectNamespace.RibbonName, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"

  • But I do not know exactly what form the data has to be in and I do not know MSBuild syntax either?
  • How might it be possible to fill the RibbonTypes attribute manually?

Solution

  • I had this problem. It was apparently caused because I changed the "Copy Local" setting on reference "Microsoft.Office.Tools.Common.v4.0.Utilities" from True to False.

    I had upgraded a project from VS2012 to VS2013 and noticed that that reference was the only one set to "Copy Local = True". So I set it to false. 'Cause it was different.