Target "copy" task doesn't run in .Net Core project if project is "up-to-date"
See original GitHub issueIssue moved from microsoft/msbuild#5450
- Please respond to @Dean-NC.
From @Dean-NC on Saturday, June 20, 2020 2:10:45 PM
Steps to reproduce
In the attached demo project, there is an external .js file that gets linked to a destination in the project, but intentionally outside the wwwroot folder, so that it can maintain it’s linked status, otherwise .Net core project system will fight and overtake it, removing the linked status after building and the copy target runs.
There’s a “copy” target set to copy any changes to the original .js file to the wwwroot/js folder so the app can use it. I want this target to run regardless of whether the project is “up-to-date” or not, so I used a BeforeTargets = “BeforeBuild” (I also tried BeforeTargets = “Build”, AfterTargets and all variations). The target runs if there’s changes to the project (C# or cshtml or .csproj), but changes to the linked .js file alone won’t trigger the target to run.
- Build the project, start project without debugging, which will run the Index.cshtml page.
- While in Visual Studio, open Linked\module1.js, and make some changes.
- Build the project in Visual Studio. Note that the updated .js file won’t get copied. If you have the Output Window verbosity set to Detailed, you will see nothing happens since the project is considered up-to-date.
Project file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup>
<ItemGroup>
<None Include="..\module1.js" Link="Linked\module1.js" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\js\common\*" Visible="False" />
<None Update="Linked\**\*" CopyToPublishDirectory="Never" />
</ItemGroup>
<Target Name="CopyLinkedFiles" BeforeTargets="BeforeBuild">
<Copy SourceFiles="%(None.Identity)" DestinationFolder="wwwroot\js\common" Condition="'%(None.Link)' != '' And '%(Extension)' == '.js'" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" />
</Target>
</Project>
The reason I’ve hidden the wwwroot\js\common files, is because these will be linked, and I don’t want to accidentally change these in the common folder, but in my “Linked” folder instead. For the ItemGroup link, I’ve tried “Content” instead of “None” which didn’t help.
Expected behavior
In my traditional .Net framework web apps, the same kind of custom Target will always run, even if the project is up-to-date. I expect the same here.
Actual behavior
The msbuild target doesn’t run if the project is up-to-date.
Environment data
.NET Core SDK (reflecting any global.json): Version: 3.1.301
Runtime Environment: OS Name: Windows OS Version: 10.0.18363 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.301\
Host (useful for support): Version: 3.1.5 Commit: 65cd789777
.NET Core SDKs installed: 3.1.300 [C:\Program Files\dotnet\sdk] 3.1.301 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft Visual Studio Community 2019 Version 16.6.0 VisualStudio.16.Release/16.6.0+30114.105 Microsoft .NET Framework Version 4.8.03752
Installed Version: Community
ASP.NET and Web Tools 2019 16.6.936.3669 ASP.NET and Web Tools 2019
ASP.NET Core Razor Language Services 16.1.0.2020603+b3ac44798c16fff5b95dbcfe62dea84aa9a1bd72 Provides languages services for ASP.NET Core Razor.
ASP.NET Web Frameworks and Tools 2019 16.6.936.3669
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (3 by maintainers)
@drewnoakes thanks for your thoughts. The
UpToDateCheckInput/Output
is an interesting thought. I don’t remember if I tried usingTargetPath
withCopyToOutputDirectory
. Let me tryTargetPath
and if that doesn’t work I’ll tryUpToDateCheckInput/Output
. I’ll let you know the results.@drewnoakes Thanks for letting me know about those input/output project settings, I had no idea they existed.