microsoft / slow-cheetah

Tooling for XML and JSON file transforms on build from Visual Studio and MSBuild
Other
323 stars 67 forks source link

Xml and config transformation does not work on UWP #257

Open soroshsabz opened 2 years ago

soroshsabz commented 2 years ago

ITNOA

transformation in UWP project dose not work when Application try to run with f5 in appx directory. it is just work in default output directory such as Debug or Release

soroshsabz commented 2 years ago

I add some question for this in Stackoverflow

And I add some question for this in Microsoft Q&A

soroshsabz commented 2 years ago

After many working I found solution, AppX Packaging is coordinate from Microsoft.AppxPackage.Targets that exists in Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage and all important target for packaging and running (f5 in Visual Studio) exists here.

As you can see in this file, Microsoft create some blank target between important target in build and packaging pipeline, so you can use override these blank targets very cleanly to control procedure of building and packaging AppX, for example you can override blow targets

      <!-- Override to specify actions to happen before generating project PRI file. -->
      <Target Name="BeforeGenerateProjectPriFile" />

or

      <!-- Override to specify actions to happen after generating project PRI file. -->
      <Target Name="AfterGenerateProjectPriFile" />

or ...

So for adding custom files into packaging I override BeforeGenerateProjectPriFile target and for adding file, I used PackagingOutputs ItemGroup for adding my file like below

  <Target Name="BeforeGenerateProjectPriFile">
    <ItemGroup>
      <PackagingOutputs Include="$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).exe.config">
        <OutputGroup>ContentFilesProjectOutputGroup</OutputGroup>
        <TargetPath>$(AssemblyName).exe.config</TargetPath>
        <ProjectName>$(ProjectName)</ProjectName>
      </PackagingOutputs>
    </ItemGroup>
  </Target>

If you want this approach in practice, I used this technique in linphone-windows10

soroshsabz commented 2 years ago

I want to make PR for adding this systemically in slow-cheetah, after merging my previous PR #261.

soroshsabz commented 2 years ago

@adrianvmsft Please assign this issue to me

thanks