5

I am playing around with the TDS task GetFilesToTransform. I want to try and transform files based on an environment variable that is not the current build configuration.

The default task definition in C:\Program Files (x86)\MSBuild\HedgehogDevelopment\SitecoreProject\v9.0\HedgehogDevelopment.SitecoreProject.targets is this:

<GetFilesToTransform
  FileExtension="config"
  SolutionConfig="$(CurrentSolutionConfigurationContents)"
  Configuration="$(Configuration)"
  SourceWebProject="$(SourceWebProject)"
  WebProjectRoot="$(MSBuildProjectDirectory)\$(SourceWebPhysicalPath)"
  WebProject="$(SourceWebVirtualPath)"
  Condition="'$(ConfigTransformAvailable)' == 'true'">
  <Output TaskParameter="TransformFilesToRemove" ItemName="TransformFilesToRemove"/>
  <Output TaskParameter="Transforms" ItemName="Transforms"/>
</GetFilesToTransform>

I assumed that the Configuration property would allow me to pass in a different variable and pickup config transforms. I have duplicated this entry and created my own build task that looks like this:

 <GetFilesToTransform
  FileExtension="config"
  SolutionConfig="$(CurrentSolutionConfigurationContents)"
  Configuration="Local"
  SourceWebProject="$(SourceWebProject)"
  WebProjectRoot="$(MSBuildProjectDirectory)\$(SourceWebPhysicalPath)"
  WebProject="$(SourceWebVirtualPath)"
  Condition="'$(ConfigTransformAvailable)' == 'true'">
  <Output TaskParameter="TransformFilesToRemove" ItemName="TransformFilesToRemove"/>
  <Output TaskParameter="Transforms" ItemName="Transforms"/>
</GetFilesToTransform>

I am using Local as the configuration. However this is task still transforming using the build configuration value of DEBUG instead of Local. Any suggestions why this happening?

This is the build log:

11>                         Task  "GetFilesToTransform"
11>                             Task Parameter:FileExtension=config
11>                             Task Parameter:SolutionConfig=<SolutionConfiguration>
11><ProjectConfiguration Project="{135a1e1b-e091-439b-97d1-6f871280e339}" AbsolutePath="F:\TDS.Master.scproj">Debug|AnyCPU</ProjectConfiguration>
11><ProjectConfiguration Project="{b4239999-0ae1-438a-842b-094a33a8a2d1}" AbsolutePath="F:\Host.csproj">Debug|AnyCPU</ProjectConfiguration>
11>                             Task Parameter:Configuration=Local
11>                             Task Parameter:SourceWebProject={b4239999-0ae1-438a-842b-094a33a8a2d1}|EC.SWP.Common.Host\EC.SWP.Common.Host.csproj
11>                             Task Parameter:WebProjectRoot=F:\Host
11>                             Task Parameter:WebProject=/Host.csproj
11>    Transforms=
11>        App_Config\Include\_Common\Sites.config
11>                TransformFile=App_Config\Include\_Common\Sites.Debug.config
11>        web.config
11>                TransformFile=web.Debug.config

1 Answer 1

2

In the above example, the SolutionConfig XML attribute is constructed by the build process. Internally, this overrides the Configuration parameter when the build supplies the SolutionConfig value.

Remove the SolutionConfig property:

<GetFilesToTransform
FileExtension="config"
Configuration="Local"
SourceWebProject="$(SourceWebProject)"
WebProjectRoot="$(MSBuildProjectDirectory)\$(SourceWebPhysicalPath)"
WebProject="$(SourceWebVirtualPath)"
Condition="'$(ConfigTransformAvailable)' == 'true'">
  <Output TaskParameter="TransformFilesToRemove" ItemName="TransformFilesToRemove"/>
  <Output TaskParameter="Transforms" ItemName="Transforms"/>
</GetFilesToTransform>

And ensure that the file in the csproj has the dependant element:

<Content Include="App_Config\Include\_Common\Sites.Local.config">
  <DependentUpon>Sites.config</DependentUpon>
  <SubType>Designer</SubType>
</Content>
1
  • Do I need to remove this line: SolutionConfig="$(CurrentSolutionConfigurationContents)" Commented Jan 30, 2017 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.