dotnet-transform-xdt icon indicating copy to clipboard operation
dotnet-transform-xdt copied to clipboard

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

Open DanielLaberge opened this issue 9 years ago • 6 comments

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.

DanielLaberge avatar Dec 20 '16 19:12 DanielLaberge

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 avatar Dec 24 '16 10:12 nil4

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

nil4 avatar Feb 18 '17 12:02 nil4

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>

LucidObscurity avatar May 31 '17 18:05 LucidObscurity

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

mieliespoor avatar May 15 '18 11:05 mieliespoor

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.

mieliespoor avatar May 15 '18 14:05 mieliespoor

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.

DanielLaberge avatar May 15 '18 15:05 DanielLaberge