microsoft / slow-cheetah

Tooling for XML and JSON file transforms on build from Visual Studio and MSBuild
Other
322 stars 67 forks source link

SlowCheetah 'File not found' issue when publishing to the file system using msbuild #284

Open trousyt opened 1 year ago

trousyt commented 1 year ago

I'm using SlowCheetah 4.0.50 and msbuild 17.5.1 on a project using PackageReference.

I'm using msbuild from the command line and publishing to the file system and it seems as though the target ScApplyWebTransforms runs before the files have been copied to obj{Config}\Publish\PublishTmp. Then when the ScApplyWebTransforms target runs, it's unable to find the files to transform in PublishTmp and errors with a FileNotFoundException.

Task "SlowCheetah.TransformTask" (TaskId:47)
  Task Parameter:Source=obj\Release\Package\PackageTmp\log4net.config (TaskId:47)
  Task Parameter:Destination=obj\Release\Package\PackageTmp\log4net.config (TaskId:47)
  Task Parameter:Transform=log4net.Production (Local Publish).config (TaskId:47)
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018: The "SlowCheetah.TransformTask" task failed unexpectedly.
 [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018: System.IO.FileNotFoundException: File not found [C:\Proje
cts\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018: File name: 'obj\Release\Package\PackageTmp\log4net.config
' [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.VisualStudio.SlowCheetah.JsonTransformer.
IsFileSupported(String filePath) [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.VisualStudio.SlowCheetah.TransformerFacto
ry.<>c__DisplayClass1_0.<GetTransformer>b__0(ITransformer tr) [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnu
merable`1 source, Func`2 predicate) [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.VisualStudio.SlowCheetah.TransformerFacto
ry.GetTransformer(String source, ITransformationLogger logger) [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.VisualStudio.SlowCheetah.TransformTask.Ex
ecute() [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft
.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets(95,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstant
iatedTask>d__26.MoveNext() [C:\Projects\TFS-Git\HNVOD\src\VODTime\VODTime.csproj]
Done executing task "SlowCheetah.TransformTask" -- FAILED. (TaskId:47)

The target depends on PipelinePreDeployCopyAllFilesToOneFolder which looks like it should run before, not after ScApplyWebTransforms to give it a chance to copy the files.

Target "ScApplyWebTransforms: (TargetId:89)" in file "C:\Users\trparkin\.nuget\packages\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.Web.targets" from project "C:\Project s\TFS-Git\HNVOD\src\VODTime\VODTime.csproj" (target "PipelinePreDeployCopyAllFilesToOneFolder" depends on it):

If I modify the Microsoft.VisualStudio.SlowCheetah.Web.targets file and comment out 'ScApplyWebTransforms;' in the PipelinePreDeployCopyAllFilesToOneFolderDependsOn property everything works:

<!-- Required for File System -->
<PipelinePreDeployCopyAllFilesToOneFolderDependsOn>
  $(PipelinePreDeployCopyAllFilesToOneFolderDependsOn);
  <!--ScApplyWebTransforms;-->
</PipelinePreDeployCopyAllFilesToOneFolderDependsOn>
trousyt commented 1 year ago

For anyone experiencing the same issue, I started importing the following targets file to fix it.

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="FixSlowCheetahFileSystemPublish" BeforeTargets="BeforeResolveReferences">
    <PropertyGroup>
      <PipelinePreDeployCopyAllFilesToOneFolderDependsOn>
        $([MSBuild]::Unescape($(PipelinePreDeployCopyAllFilesToOneFolderDependsOn.Replace('ScApplyWebTransforms', ''))))
      </PipelinePreDeployCopyAllFilesToOneFolderDependsOn>
    </PropertyGroup>
  </Target>
</Project>