我创建了代码片段中所示的ItemGroup。我需要遍历这个ItemGroup并运行EXEC命令-同样显示在代码片段中。我似乎不能让它工作。代码返回如下所示的错误(注意-该消息写入了2次,这是正确的),但是EXEC命令没有正确运行。未设置该值;因此EXEC根本不会执行。我需要EXEC执行两次,或者执行我在ItemGroup中定义的部分。
错误: 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 SECT...找不到配置节'‘。
代码片段:
<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>发布于 2010-05-04 11:14:30
问题是你一次只能批量处理两个项目。我的意思是你有语句
%(SectionsToEncrypt.Section)
%(ConfigurationToBuild.FlavorToBuild)在相同的任务调用中。当您在同一任务调用中同时批处理多个项目时,它们将是独立批处理的。这就是为什么您的错误是说明配置节'' ...
如果你的FlavorToBuild只有一个值,那么你应该做的就是在你调用Exec之前把它填充到一个属性中,然后再使用这个属性。这样一来,你的一行代码就会转换成:
<PropertyGroup>
<_FlavToBuild>%(ConfigurationToBuild.FlavorToBuild)<_FlavToBuild>
</PropertyGroup>
<Exec Command="$(AspNetRegIis) -pef "%(SectionsToEncrypt.Section)" "$(DropLocation)\$(BuildNumber)\$(_FlavToBuild)\$(AnythingPastFlavorToBuild)" -prov "$(WebSiteRSACustomProviderName)""/>如果FlavorToBuild有多个值,那就更复杂了。您将有两个选项:
批处理是MSBuild中最容易混淆的元素之一。我在http://sedotech.com/Resources#batching上整理了一些在线资源。如果你想知道更多,你可以拿一份我的book。
https://stackoverflow.com/questions/2761967
复制相似问题