Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow Custom CopyToOutputDirectory Location With TargetPath (#6237)
Fixes #2795 and indirectly fixes https://developercommunity.visualstudio.com/t/copytooutputdirectorypreservenewest-ignored-inside/1332219?from=email&viewtype=all#T-ND1363347 Context There's currently no way to include items in a project such that: Visual studio sees them in a specific folder (via <Link>). They are published to a user-defined path (currently controlled via <Link>) Changes Made Modify the AssignTargetPath task to return early if TargetPath metadata is already set on a particular item. Testing Need to add one test covering this. Tested locally with bootstrapped MSBuild on command line Tested locally with a boostrapped msbuild on internal VS Here's the repro I'm using: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> </PropertyGroup> <ItemGroup> <Content Include="Files\**"> <Link>Files\%(Filename)%(Extension)</Link> <TargetPath>%(Filename)%(Extension)</TargetPath> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> </Project> Notes The other way of solving this problem has to do with Microsoft.Common.CurrentVersion.targets. We modify it so that the AssignTargetPath task look something like this: <AssignTargetPath Files="@(Content)" RootFolder="$(MSBuildProjectDirectory)" Condition="'%(Content.TargetPath)'==''"> <Output TaskParameter="AssignedFiles" ItemName="ContentWithTargetPath" /> </AssignTargetPath> <ItemGroup> <ContentWithTargetPath Include="@(Content)" Condition="'%(Content.TargetPath)'!=''"/> </ItemGroup> This seems less efficient to me. AssignTargetPath is also called for all None, Content, and EmbeddedResource files. So if we go this batching route and want None or EmbeddedResource to have this feature, we'd need to batch those as well.
- Loading branch information
1 parent
b7476cc
commit 7804350
Showing
4 changed files
with
88 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters