dotnet / dotnet/msbuild

Item metadata not being evaluated when passed to build task assemblies

Open
#3,182 1 comment 2 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Steps to reproduce
I have a C++ XAML project with custom build logic that more or less is like this:
```xml


C:\Path\A

< Dependency Include=”B”>
C:\Path\B

@(Dependency->'%(IncludeDirs)')


%(ClCompile.AdditionalIncludeDirectories);$(ExtraIncludeDirs)


%(ResourceCompile.AdditionalIncludeDirectories);$(ExtraIncludeDirs)

```

### Expected behavior

This should compile just fine with the extra include directories passed to the compiler.

### Actual behavior

This worked fine for the most part in normal C++ projects, until I tried to use this in a C++ XAML project. Then it blew up trying to compile the XAML with an opaque “Path has invalid characters” error when invoking the XAML compiler MSBuild task. I debugged it and found out it was because the XamlCppIncludeDirectories property that gets passed to the task had a value of “@(Dependency->'%(IncludeDirs)')” rather than the actual evaluated value. For reference, here’s how that task is invoked (from C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\WindowsXaml\v15.0\8.1\Microsoft.Windows.UI.Xaml.Common.Targets):
```xml



```
Now, I expect the property value to be non-evaluated during the evaluation phase of the build per the MSBuild documentation, but that same documentation indicates that these transforms and expressions should be evaluated during the execution phase when this XAML target is executing. It seems to happen properly for the normal C++ CL task itself, which is invoked like:
```xml



%(AdditionalIncludeDirectories)

```

Talking to an MSBuild developer, it seems that the problem is that there is an issue with the items not having their default metadata evaluated by the MSBuild engine before being passed to the XAML task, so the raw property value never gets recursively evaluated before being passed in. This is due to an internal implementation detail of how ItemDefinitionGroup entries are referenced/evaluated.

Ideally properties like this would get evaluated in such cases before being passed to MSBuild task assemblies, this special condition could be more easily detectable by developers, or at minimum this limitation get documented.

### Environment data
`msbuild /version` output:
Microsoft (R) Build Engine version 15.6.85.37198 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.6.85.37198

OS info:
Windows 10 Version 1709 (OS Build 16299.309)

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
Visual Studio 2017 15.6.6

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.