Closed DanielLaberge closed 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.
Since I have not heard back from @DanielLaberge on the exact scenario, I am closing this issue. Please reopen if you have additional information.
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 "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)"" Condition="Exists('$(_XdtTransform)')" />
</Target>
@LucidObscurity Have you tried this on exe projects? This doesn't seem to work for exe projects?
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 "$(_SourceWebConfig)" --transform "$(_XdtTransform)" --output "$(_TargetWebConfig)" --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.
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.
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.