MSBuild使用ItemGroup和EXEC命令 [英] MSBuild Working with ItemGroup and EXEC Command
问题描述
我创建了代码片段中显示的ItemGroup。我需要遍历这个ItemGroup并运行EXEC命令 - 也显示在代码片段。我似乎不能让它工作。代码返回如下所示的错误(注意 - 消息被写入2次,这是正确的),但是EXEC命令运行不正确。未设置该值;因此EXEC没有执行。我需要EXEC执行两次或通过在ItemGroup中定义的部分。
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.
错误:
加密WebServer appSettings部分
加密WebServer connectionStrings部分
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -pef\gaw\UI-provRSACustomProvider
加密配置section ...
未找到配置部分。
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:
CODE SNIPPET:
<ItemGroup>
<SectionsToEncrypt Include="Item">
<Section>appSettings</Section>
</SectionsToEncrypt>
<SectionsToEncrypt Include="Item">
<Section>connectionStrings</Section>
</SectionsToEncrypt>
</ItemGroup>
<Target Name="EncryptWebServerWebConfigSections">
<Message Text="Encrypting WebServer %(SectionsToEncrypt.Section) section" />
<Exec Command="$(AspNetRegIis) -pef "%(SectionsToEncrypt.Section)" "$(DropLocation)\$(BuildNumber)\%(ConfigurationToBuild.FlavorToBuild)\$(AnythingPastFlavorToBuild)" -prov "$(WebSiteRSACustomProviderName)""/>
</Target>
推荐答案
问题是,一个时间。我的意思是你有声明
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 '' ...
如果你的FlavorToBuild只有一个值你应该做是在东西,进入一个属性,然后调用Exec,然后使用该属性。所以你的一个班轮会转换为:
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 "%(SectionsToEncrypt.Section)" "$(DropLocation)\$(BuildNumber)\$(_FlavToBuild)\$(AnythingPastFlavorToBuild)" -prov "$(WebSiteRSACustomProviderName)""/>
如果你有FlavorToBuild的多个值,那么更复杂。您将有两个选项:
If you have multiple values for FlavorToBuild then it's more complicated. You would have 2 options:
- 硬编码Exec多次
- 批处理以执行foreach / foreach
批处理是MSBuild最令人困惑的元素之一。我在 http://sedotech.com/Resources#batching 上提供了一些在线资源。如果您想了解详情,可以选择我的图书的副本。
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.
这篇关于MSBuild使用ItemGroup和EXEC命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!