views:

169

answers:

1

I created the ItemGroup shown in the code snippet. I need to iterate through this ItemGroup and run the EXEC command - also shown in the code snippet. I cannot seem to get it to work. The code returns the error shown below (note - the Message is written 2 times, which is correct), but the EXEC Command is not running correctly. The value is not being set; therefore the EXEC is not executing at all. I need the EXEC to execute twice or by however sections I define in the ItemGroup.

ERROR: Encrypting WebServer appSettings section Encrypting WebServer connectionStrings section C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef "" "\gaw\UI" -prov "RSACustomProvider" Encrypting configuration section... The configuration section '' was not found.

CODE SNIPPET: appSettings

connectionStrings


<Exec Command="$(AspNetRegIis) -pef &quot;%(SectionsToEncrypt.Section)&quot; &quot;$(DropLocation)\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\$(AnythingPastFlavorToBuild)&quot; -prov &quot;$(WebSiteRSACustomProviderName)&quot;"/>

+2  A: 

The problem is that you are batching on 2 items at a time. What I mean is the you have the statements

%(SectionsToEncrypt.Section)
%(ConfigurationToBuild.FlavorToBuild)

In the same task invocation. When you batch on more than 1 item at a time in the same task invocation, they will be batch independently. That's why you're error is stating The configuration section '' ...

If you your FlavorToBuild just has one value what you should do is to stuff that into a property before you call to Exec and then use the property. So your one liner would then convert to:

<PropertyGroup>
    <_FlavToBuild>%(ConfigurationToBuild.FlavorToBuild)<_FlavToBuild>
</PropertyGroup>
<Exec Command="$(AspNetRegIis) -pef &quot;%(SectionsToEncrypt.Section)&quot; &quot;$(DropLocation)\$(BuildNumber)\$(_FlavToBuild)\$(AnythingPastFlavorToBuild)&quot; -prov &quot;$(WebSiteRSACustomProviderName)&quot;"/>

If you have multiple values for FlavorToBuild then it's more complicated. You would have 2 options:

  1. Hard code Exec more than once
  2. Use target batching with task batching to perform the foreach/foreach

Batching is one of the most confusing elements of MSBuild. I've put together some online resources at http://sedotech.com/Resources#batching. If you want to know more than that then you can pick up a copy of my book.

Sayed Ibrahim Hashimi
+1 And can highly recommend the book - replaces weeks of "aha, so that's waht I didnt get" with a proper top to bottom tour.
Ruben Bartelink