slow-cheetah icon indicating copy to clipboard operation
slow-cheetah copied to clipboard

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

Open Jeky-v opened this issue 6 years ago • 4 comments

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: <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

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

Jeky-v avatar May 24 '18 06:05 Jeky-v

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.

paulomorgado avatar Jun 06 '18 09:06 paulomorgado

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

ig-sinicyn avatar Jul 02 '18 14:07 ig-sinicyn

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>

kernelcoredump avatar Jun 23 '19 05:06 kernelcoredump

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/

andrewwburns avatar Jan 21 '20 10:01 andrewwburns