microsoft / slow-cheetah

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

Transformations doesn't work properly in Web project with package reference format when building it using msbuild. #133

Open Jeky-v opened 6 years ago

Jeky-v commented 6 years ago

When i use package reference format all targets from installed packages are imported with <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> import in *.csproj file.

In web projects by default in *.csproj file placed several imports in next order: `

`

When i'm trying to build and publish such solution with msbuild using next command: msbuild.exe "C:\PATH\Web.Site.sln" /nologo /nr:false /p:DeployOnBuild=true /p:PublishProfile="FileSystem.pubxml" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0" /m /verbosity:normal transformation for all files except Web.config is not applied. But in case of changing order of import targets in *.csproj to the next one:

Microsoft.WebApplication.targets Microsoft.CSharp.targets

transformations begin to work.

More details in stackoverflow question

paulomorgado commented 6 years ago

The transformations are applied, but the transformed files are removed from the list of files to copy in the CopyAllFilesToSingleFolderForPackage target from Microsoft.Web.Publishing.targets.

    <ItemGroup>
      <_AllExtraFilesUnderTempFolder Include="$(WPPAllFilesInSingleFolder)\**" />
      <_AllExtraFilesUnderTempFolder
        Remove="@(FilesForPackagingFromProject->'$(WPPAllFilesInSingleFolder)\%(DestinationRelativePath)')" />
    </ItemGroup>

Changing the order of targets does solve the problem.

The change causes target ScApplyWebTransforms to be called at the end of the CopyAllFilesToSingleFolderForPackage instead of before.

ig-sinicyn commented 6 years ago

Any updates on this?

We have same issue, but changing order of imports does not work for us as It does not work together with Microsoft.CodeDom.Providers.DotNetCompilerPlatform 2.0 package

kernelcoredump commented 5 years ago

As I described in https://github.com/microsoft/slow-cheetah/issues/182#issuecomment-504721421, I use the following workaround in my publish profiles:

  <PropertyGroup>
    <CopyAllFilesToSingleFolderForMsdeployDependsOn>
      CollectCustomFiles;
      $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
    </CopyAllFilesToSingleFolderForMsdeployDependsOn>
  </PropertyGroup>
  <Target Name="CollectCustomFiles">
    <ItemGroup>
      <FilesForPackagingFromProject Remove="@(ContentWithTargetPath->'%(OriginalItemSpec)')" />
      <FilesForPackagingFromProject Include="@(ContentWithTargetPath)" Exclude="@(AppConfigWithTargetPath)">
        <DestinationRelativePath>%(ContentWithTargetPath.TargetPath)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
andrewwburns commented 4 years ago

I found that I had to change the order of two items in my .csproj files, as show at: https://blog.vitaliitylyk.com/slowcheetah-and-nuget-packagereference-format/