Itiviti / gradle-msbuild-plugin

Gradle plugin for msbuild execution, supports C# project files for now
Apache License 2.0
101 stars 58 forks source link

InvalidProjectFileException error during project file parsing #101

Closed krisztiankocsis closed 5 years ago

krisztiankocsis commented 5 years ago

Hi!

I've an issue during the execution of msbuild Build target, which was working with older VS versions before.

Environment:

This is important to us now, so I can provide help, also coding help if necessary!

Error during project file parsing: Microsoft.Build.Exceptions.InvalidProjectFileException: Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries($(TargetFrameworkIdentifier), $(TargetFrameworkVersion), $(TargetFrameworkProfile), $(PlatformTarget), $(TargetFrameworkRootPath), $(TargetFrameworkFallbackSearchPaths))". Method 'Microsoft.Build.Utilities.ToolLocationHelper.GetPathToStandardLibraries' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a, b)). C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1) at Microsoft.Build.Evaluation.Expander2.Function1.Execute(Object objectInstance, IPropertyProvider1 properties, ExpanderOptions options, IElementLocation elementLocation) at Microsoft.Build.Evaluation.Expander2.PropertyExpander1.ExpandPropertyBody(String propertyBody, Object propertyValue, IPropertyProvider1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties) at Microsoft.Build.Evaluation.Expander2.PropertyExpander1.ExpandPropertiesLeaveTypedAndEscaped(String expression, IPropertyProvider1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties) at Microsoft.Build.Evaluation.Expander2.PropertyExpander1.ExpandPropertiesLeaveEscaped(String expression, IPropertyProvider1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties) at Microsoft.Build.Evaluation.Expander2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation) at Microsoft.Build.Evaluation.Evaluator4.EvaluatePropertyElement(ProjectPropertyElement propertyElement) at Microsoft.Build.Evaluation.Evaluator4.EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.Evaluate(ILoggingService loggingService, BuildEventContext buildEventContext) at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary2 globalProperties, String toolsVersion) at ProjectFileParser.ProjectHelpers.LoadProject(String fullPath, IDictionary`2 args) at ProjectFileParser.Program.ParseProject(String file, JObject args) at ProjectFileParser.Program.Parse(String file, JObject args) at ProjectFileParser.Program.Main(String[] args)

ngyukman commented 5 years ago

Hi @krisztiankocsis

it seems to be related to https://developercommunity.visualstudio.com/content/problem/311136/update-to-1580-projects-wont-load.html

krisztiankocsis commented 5 years ago

Thanks, it did help, but I had to install all DLLs in MSBuild directory, even if it was not recommended...

ngyukman commented 5 years ago

I am not sure but I guess there is some misconfiguration in the system previously

ghost commented 5 years ago

Hello @krisztiankocsis could you share more details on how you fixed this issue? I'm facing exactly the same issue.

ngyukman commented 5 years ago

hi @QianCheng40 did you try the solution in https://developercommunity.visualstudio.com/solutions/311740/view.html ?

ghost commented 5 years ago

Hi @ngyukman thanks for quick reply. I don't have Microsoft.Build.* assemblies in GAC so no need to run those "gacutil \u" commands I assume.

I have both VS2015 and VS2017 installed on my machine. The solution I'm trying to build was created by VS2015 so I also tried:

msbuild { version = "14.0" }

but still got the same error (where VS2017 tools still seem to be used)

ngyukman commented 5 years ago

Hi @QianCheng40

sorry that I was pointing you the incorrect part, it should be https://developercommunity.visualstudio.com/comments/312467/view.html about installing them in gac

we had similar issue also when having both msbuild installed in workstation and it can be fixed by installing them into gac

ghost commented 5 years ago

Ok, this worth a try although it's not recommended. I don't have admin permission to my work machine required to run 'gacutl /i' right now. Will let you know the result once I get it run. Thank you!

ghost commented 5 years ago

Fixed by installing those assemblies (and System.Collections.Immutable.dll) in GAC now.

gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Engine.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Conversion.Core.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\System.Collections.Immutable.dll"

Ideally, the ProjectFileParser shouldn't have to load those assemblies from GAC.

Thanks & Regards