Le Microsoft EventRegister Tool crée un fichier manifeste d'instrumentation avec un fichier de ressources lors de la compilation du projet. Je voudrais déplacer ces fichiers vers un autre chemin après la compilation et changer deux attributs dans le fichier manifeste d'instrumentation avec msbuild. Les valeurs des attributs sont les mêmes, chacune représentant le chemin du fichier de ressources d'accompagnement. Il semble que je ne peux pas obtenir la syntaxe pour modifier les attributs avec msbuild droite, et je pense qu'il a quelque chose à voir avec deux choses. D'abord, le fichier manifeste d'instrumentation ne contient pas de déclaration de fichier xml classique. Deuxièmement, le manifeste d'instrumentation comprend des espaces de noms.Comment modifier la valeur d'un attribut dans un manifeste d'instrumentation avec msbuild?
Ce que je suis venu avec jusqu'à présent, grâce au blog "Updating XML files with MSBuild" by Sayed Ibrahim Hashimi, est la suivante:
<PropertyGroup>
<SourceManifestAssembly>$(OutputPath)Name.etwManifest.dll</SourceManifestAssembly>
<DestinationManifestAssembly>$(Programdata)\MyCompany\MyProduct\1.0.0.0\Name.etwManifest.dll</DestinationManifestAssembly>
<SourceManifest>$(OutputPath)Name.etwManifest.man</SourceManifest>
<DestinationManifest>$(Programdata)\MyCompany\MyProduct\1.0.0.0\Name.etwManifest.man</DestinationManifest>
</PropertyGroup>
<ItemGroup>
<UpdateManifest Include="UpdatemessageFileName">
<NewValue>$(DestinationManifestAssembly)</NewValue>
<Namespaces><Namespace Prefix='x' Uri='http://schemas.microsoft.com/win/2004/08/events' /></Namespaces>
<XPath>//x:events/provider/@messageFileName</XPath>
</UpdateManifest>
<UpdateManifest Include="UpdateresourceFileName">
<NewValue>$(DestinationManifestAssembly)</NewValue>
<Namespaces><Namespace Prefix='x' Uri='http://schemas.microsoft.com/win/2004/08/events' /></Namespaces>
<XPath>//x:events/provider/@resourceFileName</XPath>
</UpdateManifest>
</ItemGroup>
<Target Name="AfterBuild">
<Copy SourceFiles="$(SourceManifestAssembly)" DestinationFiles="$(DestinationManifestAssembly)" />
<Copy SourceFiles="$(SourceManifest)" DestinationFiles="$(DestinationManifest)" />
<XmlPoke XmlInputPath="$(DestinationManifest)" Query="%(UpdateManifest.XPath)" Value="%(UpdateManifest.NewValue)" Namespaces="%(UpdateManifest.Namespaces)" />
</Target>
Cela prend soin de la copie, mais il ne change pas les valeurs d'attribut.
Le fichier manifeste d'instrumentation ressemble à ceci:
<instrumentationManifest xmlns="http://schemas.microsoft.com/win/2004/08/events">
<instrumentation xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:win="http://manifests.microsoft.com/win/2004/08/windows/events">
<events xmlns="http://schemas.microsoft.com/win/2004/08/events">
<provider name="MyCompany-MyProduct-MyLog" guid="{658FE45E-C2D4-4E73-82BB-6441A0348D9B}" resourceFileName="C:\Documents\Visual Studio\Projects\Name\bin\Debug\Name.etwManifest.dll" messageFileName="C:\Documents\Visual Studio\Projects\Name\bin\Debug\Name.etwManifest.dll" symbol="MyCompanyMyProductMyLog">
</provider>
</events>
</instrumentation>
Les attributs qui doivent être changés sont //provider/@resourceFileName
et //provider/@messageFileName
.