-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Milestone
Description
(Filing bugs from my notes after customer visit exploring porting large WPF app to .NET core 3)
This:
<ItemGroup>
<Page Include="..\X\**\*.xaml" LinkBase="Y" />
</ItemGroup>Does not work as it does for Compile, EmbeddedResource, AdditionalFiles, EmbeddedResource:
sdk/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets
Lines 201 to 246 in 9543229
| <!-- | |
| Automatically add Link metadata to items of specific types if they are outside of the project folder and don't already have the Link metadata set. | |
| This will cause them to be shown in the Solution Explorer. If an item has LinkBase metadata, the automatic Link will start with that value, and | |
| the items will appear in the Solution Explorer under the folder specified by LinkBase. | |
| --> | |
| <ItemGroup Condition="'$(SetLinkMetadataAutomatically)' != 'false'"> | |
| <Compile Update="@(Compile)"> | |
| <!-- First, add a trailing slash to the LinkBase metadata if necessary. This allows us to use the same value | |
| for the Link metadata whether or not LinkBase metadata is set: %(LinkBase)%(RecursiveDir)%(Filename)%(Extension) | |
| Note that RecursiveDir already includes the trailing slash. | |
| --> | |
| <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase> | |
| <!-- Set the Link metadata if it's not already set, if the item wasn't defined in a shared project, and the item is outside of the project directory. | |
| Check whether the item was defined in a shared project by checking whether the extension of the defining project was .projitems. | |
| Check whether an item is inside the project directory by seeing if the FullPath starts with EnsureTrailingSlash(MSBuildProjectDirectory) | |
| The FullPath and the MSBuildProjectDirectory will both already be normalized full paths. | |
| The call to [MSBuild]::ValueOrDefault() is there in order to allow calling StartsWith on the FullPath value, since it's | |
| not possible to call a string method on a metadata item directly. The intrinsic ValueOrDefault() will be more | |
| performant than calling String.Copy(), which has been used for this in other contexts, but actually makes a copy | |
| of the string data. | |
| --> | |
| <Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link> | |
| </Compile> | |
| <AdditionalFiles Update="@(AdditionalFiles)"> | |
| <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase> | |
| <Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link> | |
| </AdditionalFiles> | |
| <None Update="@(None)"> | |
| <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase> | |
| <Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link> | |
| </None> | |
| <Content Update="@(Content)"> | |
| <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase> | |
| <Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link> | |
| </Content> | |
| <EmbeddedResource Update="@(EmbeddedResource)"> | |
| <LinkBase Condition="'%(LinkBase)' != ''">$([MSBuild]::EnsureTrailingSlash(%(LinkBase)))</LinkBase> | |
| <Link Condition="'%(Link)' == '' And '%(DefiningProjectExtension)' != '.projitems' And !$([MSBuild]::ValueOrDefault('%(FullPath)', '').StartsWith($([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))))">%(LinkBase)%(RecursiveDir)%(Filename)%(Extension)</Link> | |
| </EmbeddedResource> | |
| </ItemGroup> |
This has two consequences:
- It prevents the easy way of getting these files outside project cone to show in sln explorer
- Xaml interpretation can actually change based on the Link so the impact of not generating a Link as expected can change the application behavior. I forget the details here, but I observed this in customer app.
I'm unsure if the WindowsDesktop SDK should be handling it or if we should add to above. We probably need to do this for Resource items as well.
Metadata
Metadata
Assignees
Labels
No labels