Description
I get the following build error with the latest MSBuild version:
C:\Development\ws\Main\Environment\Targets\TomSun.Targets.SmartInclude.targets(11,7): error MSB4184: The expression "[S
ystem.IO.File]::ReadAllText(%(FullPath))" cannot be evaluated. Could not find file 'C:\Development\ws\Main\Environment
Builds%(FullPath)'. [C:\Development\ws\Main\Environment\Builds\BuildAndPlugins.csproj]
The itemgroup that contains the code which leads to the error:
<ItemGroup>
<SmartIncludeContent Include="@(SmartInclude)">
<Content>$([System.IO.File]::ReadAllText(%(FullPath)))</Content>
<IncludeType>$([System.String]::new(%(Content)).Split('|').GetValue(0))</IncludeType>
<DirectoryPart>$([System.String]::new(%(Content)).Split('|').GetValue(1))</DirectoryPart>
<FilePart>$([System.String]::new(%(Content)).Split('|').GetValue(2))</FilePart>
<DirectoryRelative>$([System.IO.Path]::Combine($(MSBuildProjectDirectory),%(DirectoryPart)))</DirectoryRelative>
<DirectoryAbsolute>$([System.IO.Path]::GetFullPath(%(DirectoryRelative)))</DirectoryAbsolute>
<Files>$([System.IO.Directory]::GetFiles(%(DirectoryAbsolute),%(FilePart),SearchOption.AllDirectories))</Files>
<OriginalRelativeDir>%(RelativeDir)</OriginalRelativeDir>
<LinkRequired>$([System.String]::new(%(Content)).Contains('..\'))</LinkRequired>
<Link Condition="%(LinkRequired)">%(OriginalRelativeDir)%(FileName)%(Extension)</Link>
</SmartIncludeContent>
<SmartIncludeFiles Include="@(SmartIncludeContent -> Metadata('Files'))">
</SmartIncludeFiles>
</ItemGroup>
The itemgroup is defined directly under the project node, not within a target. It seems that accessing/evaluating item meta data within the itemgroup itself doesn't work anymore or the processing order of property functions and item meta data evaluation changed. I didn't have such issues with the previous MSBuild versions (<= MSBuild of VS2017Update2). Is that a known bug? Is that an intended behavior change? (Don't hope so)
Unfortunately that bug breaks my build at many places. Thats just one example where it hits me.
Is there a way to get back the old MSBuild behavior when you have already installed VS2017 Update 3?
Oh I just recognized that it also prevents me from opening the projects in Visual Studio. Which means i can't do anything anymore with Update 3 installed. I really need help on this.
Update:
It seems that the issue had been found here #1932 and the guys dealing with it thought it is fixed, but from my point of view it is not fixed.
Update2:
I played a bit around, here is another example. There seem to be different behaviors between the property functions (e.g. string::new and MSBuild::Add):
<SmartProjectReference Include="@(SmartProjectReferenceWorkaround2)">
<Ok1>$([System.String]::new('%(HelpIndex)'))</Ok1>
<Ok2>$([System.String]::new('%(StartSearchPatternLength)'))</Ok2>
<Ok3>$([MSBuild]::Add(1,2 ))</Ok3>
<Fails>$([MSBuild]::Add(%(HelpIndex),%(StartSearchPatternLength) ))</Fails>
</SmartProjectReference>
Ok1-3 do what you would expect. They evaluate and calculate fine.
Ok1 and Ok2 were the cases been fixed with #1932
However, the add call for the MetaValue 'Fails' leads to the following build error:
Invalid static method invocation syntax: "[MSBuild]::Add(%(HelpIndex),%(StartSearchPatternLength) )". Method '[MSBuild]::Add' not found. Static method invocation should be of the form:
$([FullTypeName]::Method()), e.g. $ ([System.IO.Path]::Combine(a
,b
)).
Update3:
I could reduce the issue down to such a simple, strange difference between two property functions:
<SimpleSample>
<Value>5</Value>
<Ok>$([System.String]::new('%(Value)'))</Ok>
<BuildFailure>$([System.Int32]::Parse('%(Value)'))</BuildFailure>
</SimpleSample>