Benötigen Sie Hilfe mit diesem MSBuild-Code.MSBuild Merge Artikelgruppen
Ich möchte 4 app.config-Dateien mit unterschiedlichen Einstellungen generieren und 2 Setup-Dateien für QA und Produktion erstellen.
Jede Setup-Datei hat 2 physische Installationen (Produktionslinien).
Also QA-Setup sollte 2 app.configs mit Qa-Einstellungen für Produktionslinie 1 und 2, das gleiche für die Produktionseinrichtung enthalten.
Hier ist ein Auszug aus dem Msbuild, das ich bisher habe.
<ItemGroup>
<BuildEnvironment Include="QA">
<Server>qa-server</Server>
<BuildEnvironment/>
<BuildEnvironment Include="Prod">
<Server>prod-server</Server>
<BuildEnvironment/>
<Line Include="1">
<Setting>A</Setting>
</Line>
<Line Include="2">
<Setting>B</Setting>
</Line>
<ItemGroup>
<Target Name="PublishSetup" Inputs="@(BuildEnvironment)" Outputs="%(BuildEnvironment.Identity)">
<!-- Doesn't work at all -->
<ItemGroup>
<AppConfig Include="@(BuildEnvironment);@(Line)">
<Path>$(MyOutDir)\App.Config-%(Identity)</Path>
</AppConfig>
</ItemGroup>
<!-- Copy app.config to the four new files -->
<Copy SourceFiles="$(AppConfigFile)" DestinationFiles="%(AppConfig.Path)" />
<!-- Update each new app.config with XmlUpdate (community task), something like the following -->
<XmlUpdate XmlFileName="%(AppConfig.Path)" XPath=".." Value="%(AppConfig.Server)" />
<XmlUpdate XmlFileName="%(AppConfig.Path)" XPath=".." Value="%(AppConfig.Setting)" />
<!-- Build 2 setup.exe, one for qa and one prod using a Exec-task passing in qa and prod as command line argument -->
<Exec Command="setupcompiler.exe /d%(BuildEnvironment.Identity)" />
</Target>
Der resultierende 4 app.configs sollte so sein, dies
app.config-QA-1
<connectionstring datasource="qa-server" ../>
<applicationSetting name="aName" value="A" />
app.config-QA-2
<connectionstring datasource="qa-server" ../>
<applicationSetting name="aName" value="B" />
app.config-Prod-1
<connectionstring datasource="prod-server" ../>
<applicationSetting name="aName" value="A" />
app.config-Prod-2
<connectionstring datasource="prod-server" ../>
<applicationSetting name="aName" value="B" />
Ihre xml haben Syntaxfehler, kannst du zuerst sicherstellen, dass es ein gültiger msbu ist ild, und geben Sie auch genauer an, wie genau die resultierende AppConfig aussehen sollte (zB wenn Sie sie manuell als ItemGroup deklarieren würden)? – stijn
Vielen Dank für Ihren Kommentar, ich habe die Frage aktualisiert. Hoffnungen, es macht jetzt mehr Sinn. – Karsten