Transformed config file is not copied to the output directory of he referencing project

14 Views Asked by At

Consider 2 net6 projects.

MainProject references LibProject.

LibProject has a custom config file (xml) as custom.config.

I created a transform as below in the LibProject.csproj.

    <Target Name="ApplyXdtCustomConfigTransform" AfterTargets="AfterCompile">
        <Message Importance="high" Text="$(OutDir) Running custom task (Target Name 'ApplyXdtCustomConfigTransform') from '$(MSBuildProjectFile)' to transform 'custom.config'.%0aReference - https://github.com/nil4/dotnet-transform-xdt, https://medium.com/we-code/config-transformation-for-net-core-f5abfaa78807 %0aTransforming '$(MSBuildThisFileDirectory)custom.config' using transform '$(MSBuildThisFileDirectory)custom.$(Configuration).config'" />
        <PropertyGroup>
            <_SourceConfig>$(MSBuildThisFileDirectory)custom.config</_SourceConfig>
            <_XdtTransform>$(MSBuildThisFileDirectory)custom.$(Configuration).config</_XdtTransform>
            <_TargetConfig>$(TargetDir)custom.config</_TargetConfig>
        </PropertyGroup>
        <Exec Command="dotnet xdt --verbose --xml &quot;$(_SourceConfig)&quot; --transform &quot;$(_XdtTransform)&quot; --output &quot;$(_TargetConfig)&quot;" Condition="Exists('$(_XdtTransform)')" />
        <Message Importance="high" Text="Transformation completed, file saved as '$(_TargetConfig)'" />
    </Target>

With this transform, the transformed custom.config is created in LibProject\bin\Release\net6.0 folder but it does not get copied in MainProject\bin\Release\net6.0.

Both Custom.config and Custom.release.config files are marked as Build Action = 'None' and Copy To Output Directory = 'Do not copy'.

Is there any way to copy the transformed custom.config to MainProject\bin\Release\net6.0 without mentioning any path of MainProject, as LibProject may get referenced by other projects too?

0

There are 0 best solutions below