nil4 / dotnet-transform-xdt

Modern .NET tools and library for XDT (Xml Document Transformation)
Apache License 2.0
118 stars 12 forks source link

Add info about publishing console apps #29

Closed xumix closed 3 years ago

xumix commented 6 years ago

Thank for your project!

This config works for me:

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Xdt.Tools" Version="2.0.0" />
  </ItemGroup>
  <Target Name="ApplyXdtConfigTransform" BeforeTargets="_CopyAppConfigFile">
    <PropertyGroup>
      <_SourceWebConfig>@(AppConfigWithTargetPath)</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>@(AppConfigWithTargetPath)</_TargetWebConfig>
    </PropertyGroup>
    <Exec
        Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;"
        Condition="Exists('$(_XdtTransform)')" />
  </Target>
nil4 commented 6 years ago

Hi @xumix! Glad to hear you found a way to apply transforms for console apps.

And thank you for sharing it, I'm sure it will be helpful for others as well.

Dunge commented 3 years ago
      <_TargetWebConfig>@(AppConfigWithTargetPath)</_TargetWebConfig>

This does not seems right because it change the original file (app.config in your source control) instead of the target.

Changing it to:

      <_TargetWebConfig>$(TargetDir)$(TargetFileName).config</_TargetWebConfig>

Seems to apply it correctly to the final /bin/configuration/platform/ folder.