sensslen / nuget-license

.NET Core tool to print or save all the licenses of a project
Apache License 2.0
42 stars 8 forks source link

Microsoft.Build.Exceptions.InvalidProjectFileException #96

Open KostadinMinov opened 1 day ago

KostadinMinov commented 1 day ago

Problem

I am using .NET Framework 4.7.2 in an old project and below is the error message I get. The error doesn't appear when I build the project - only when i run the nuget-license command against it. I also tried adding net472 as --target-framework argument but without success.

"Solution"

I solved this manually through moving my VisualStudio folder to the directory the MSBuild is looking for as shown here. This isn't ideal as every other developer who has to run the project has to do the same.

The error:

Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "C:\Program Files\dotnet\sdk\8.0.403\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\8.0.403\Microsoft\VisualStudio\v17.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk. 
13>     at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
13>     at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1)
13>     at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String unescapedExpression, Boolean throwOnFileNotExistsError, List`1& imports)
13>     at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult)
13>     at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
13>     at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
13>     at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
13>     at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
13>     at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, IDirectoryCacheFactory directoryCacheFactory, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
13>     at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
13>     at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
13>     at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, Boolean interactive)
13>     at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory, Boolean interactive)
13>     at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
13>     at NuGetUtility.Wrapper.MsBuildWrapper.MsBuildAbstraction.GetProject(String projectPath) in D:\a\nuget-license\nuget-license\src\NuGetUtility\Wrapper\MsBuildWrapper\MsBuildAbstraction.cs:line 30
13>     at NuGetUtility.ReferencedPackagesReader.ReferencedPackageReader.GetInstalledPackages(String projectPath, Boolean includeTransitive, String targetFramework) in D:\a\nuget-license\nuget-license\src\NuGetUtility\ReferencedPackagesReader\ReferencedPackageReader.cs:line 30
13>     at NuGetUtility.Program.<>c__DisplayClass40_0.<OnExecuteAsync>b__1(String p) in D:\a\nuget-license\nuget-license\src\NuGetUtility\Program.cs:line 131
sensslen commented 1 day ago

nuget-license makes use of https://github.com/microsoft/MSBuildLocator and https://www.nuget.org/packages/Microsoft.Build. Would you mind reporting the issue there?