nil4 / dotnet-transform-xdt

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

Support for asp.net core projects targeting full .net framework #1

Closed DanielLaberge closed 7 years ago

DanielLaberge commented 7 years ago

We could not get this working, probably because our project targets the net46 framework.

Would you consider adding support for this use case, or suggest a work-around?

Thanks.

nil4 commented 7 years ago

Could you share a bit more detail on what you tried, and particularly what did not work? In order for me to understand what the issue is, it would be helpful if you could share a sample project and the steps you tried.

Just to note, I am using this tool myself in an ASP.NET Core project that targets both netcoreapp1.0 and net461 and it's working well.

nil4 commented 7 years ago

Since I have not heard back from @DanielLaberge on the exact scenario, I am closing this issue. Please reopen if you have additional information.

LucidObscurity commented 7 years ago

Just a note on something I found. When targeting the .net framework in asp.net core, assembly binding information is added to the [app name].config file in the publish \out directory. If you want to transform your App.config file, you need to use the modified file in the publish directory as the source or else you may get binding errors when running your application.

<Target Name="ApplyXdtConfigTransform" BeforeTargets="_TransformWebConfig">
    <PropertyGroup>
      <_SourceWebConfig>$(PublishDir)$(TargetFileName).config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(PublishDir)$(TargetFileName).config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
</Target>
mieliespoor commented 6 years ago

@LucidObscurity Have you tried this on exe projects? This doesn't seem to work for exe projects?

mieliespoor commented 6 years ago

I managed to get it working by doing the following:

<Target Name="ApplyXdtConfigTransform" AfterTargets="Build">
    <PropertyGroup>
      <_SourceWebConfig>$(OutputPath)$(TargetFileName).config</_SourceWebConfig>
      <_XdtTransform>$(MSBuildThisFileDirectory)App.$(Configuration).config</_XdtTransform>
      <_TargetWebConfig>$(OutputPath)$(TargetFileName).config</_TargetWebConfig>
    </PropertyGroup>
    <Exec Command="dotnet transform-xdt --xml &quot;$(_SourceWebConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetWebConfig)&quot; --verbose" Condition="Exists('$(_XdtTransform)')" />
  </Target>

So I changed the BeforeTargets to AfterTargets="Build". Not the most elegant, but it works for the purpose I need it to.

DanielLaberge commented 6 years ago

We ended up moving away from Xdt transforming in favor of .net core's new Configuration facilities. Thanks for the workaround, it might yet be useful to others.