0

I am trying to make an install script with powershell using the microsoft build api. I know how I can do what I want in C#, I have tested a little example, and almost got it ready in powershell. I only need to know what to fill in as key value pair.

C#:

ProjectItemGroupElement slItemGroup = project.Xml.CreateItemGroupElement();
project.Xml.InsertAfterChild(slItemGroup, project.Xml.LastChild);
List<KeyValuePair<string, string>> metadata = new List<KeyValuePair<string, string>>();
var testkvp = new KeyValuePair<string, string>(@"HintPath",@"MyPath");
metadata.Add(testkvp);
slItemGroup.AddItem(@"Reference", @"microsoft.deployment.windowsinstaller", metadata);

In powershell I got as far as this, which works, but I have no idea how to define the third parameter. Can you give me a hint?

$itemGroup = $msBuildProj.Xml.CreateItemGroupElement()
$msBuildProj.Xml.InsertBeforeChild($itemGroup, $myImport)
$itemGroup.AddItem('Reference', 'Microsoft.Deployment.WindowsInstaller')
#$itemGroup.AddItem('Reference', 'Microsoft.Deployment.WindowsInstaller', ???)
Marc W
  • 89
  • 1
  • 8

1 Answers1

0

I'm pretty sure what you want is a Dictionary object like this:

$metadata = New-Object 'System.Collections.Generic.Dictionary[String, String]'
$metadata.add('HintPath','MyPath')
$itemGroup.AddItem('Reference', 'Microsoft.Deployment.WindowsInstaller', $metadata)

That creates the dictionary, adds the key/value pair, and then uses it to create the item.

TheMadTechnician
  • 34,906
  • 3
  • 42
  • 56