dotnet / upgrade-assistant

A tool to assist developers in upgrading .NET Framework applications to .NET 6 and beyond
MIT License
1.09k stars 159 forks source link

Exception when processing an relative path for an Import directive for a projitems file #1504

Open ycholette opened 11 months ago

ycholette commented 11 months ago

Describe the bug

My csproj contains this line <Import Project="..\Shared\Shared.projitems" Label="Shared" />
and the tool outputs an exception (see exception section).

The tool is ran in the root directory where the solution is located, but projects are in sub directories, so the tool is invoke like this:

upgrade-assistant upgrade ProjectFolder\ProjectFolder.csproj

The projitems is located at Shared/Shared.projitems

To Reproduce

Run the tool like this upgrade-assistant upgrade ProjectFolder\ProjectFolder.csproj and have an import directive with a relative path.

Exceptions (if any)

> Microsoft.UpgradeAssistant.Transformers.ProjectSdkStyleTransformer
>         info: Converting project '(project file redacted).csproj' to SDK style.
>         error: Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project
> "C:\Users\(username redacted)\AppData\Local\Temp\UpgradeAssistant\Projects\088CA948-6AB7-4511-A774-2900C1AABD3A\Shared\Shared.projitems" was not found. Confirm that the expression in the
> Import declaration "..\Shared\Shared.projitems" is correct, and that the file exists on disk.
> C:\Users\(username redacted)\AppData\Local\Temp\UpgradeAssistant\Projects\088CA948-6AB7-4511-A774-2900C1AABD3A\2023-07-24--15-43-02\VS2022.csproj
>    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.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpression(String directoryOfImportingFile, ProjectImportElement importElement, String
> unescapedExpression, Boolean throwOnFileNotExistsError, List`1& imports)
>    at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement,
> List`1& projects, SdkResult& sdkResult)
>    at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
>    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
>    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
>    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
>    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, ProjectRootElementCacheBase
> projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean
> interactive)
>    at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext
> evaluationContext)
>    at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext
> evaluationContext)
>    at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings,
> EvaluationContext evaluationContext, Boolean interactive)
>    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)
>    at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
>    at MSBuild.Abstractions.UnconfiguredProject.LoadProjects(ProjectCollection collection, ImmutableDictionary`2 globalProperties, String projectFilePath) in
> D:\a\_work\1\s\src\Experiments\UpgradeAssistant\msbuild\Abstractions\UnconfiguredProject.cs:line 31
>    at MSBuild.Abstractions.MSBuildConversionWorkspace..ctor(ImmutableArray`1 paths, Boolean noBackup, String tfm, Boolean keepCurrentTFMs, Boolean forceWeb, String
> actualProjectPath) in D:\a\_work\1\s\src\Experiments\UpgradeAssistant\msbuild\Abstractions\MSBuildConversionWorkspace.cs:line 57
>    at MSBuild.Abstractions.MSBuildConversionWorkspaceLoader.LoadWorkspace(String path, Boolean noBackup, String tfm, Boolean keepCurrentTFMs, Boolean forceWeb, String
> actualProjectPath) in D:\a\_work\1\s\src\Experiments\UpgradeAssistant\msbuild\Abstractions\MSBuildConversionWorkspaceLoader.cs:line 45
>    at Microsoft.UpgradeAssistant.TryConvert.Slices.Services.TryConvertService.ConvertAsync(OperationContext context, String projectFilePath, TargetFramework targetFramework,
> ILogger logger, CancellationToken cancellationToken) in D:\a\_work\1\s\src\Experiments\UpgradeAssistant\msbuild\Slices\Services\TryConvertService.cs:line 39

Further technical details

Nageena commented 10 months ago

Any updates on the issue. I am facing exact same issue for my referenced shared project.

agr commented 9 months ago

Same happens in 0.5.261.51392

slidonnici commented 8 months ago

I also have the same issue, but I don't have any Import Project, just some Reference Include with relative path in the HintPath tag.

ericnewton76 commented 2 months ago

This also happens if you have a node like:

<ItemGroup>
    <None Include="NLog.config" />
</ItemGroup>

and the NLog.config file is missing.

errr... maybe not. idk. error message given by ProjectSdkStyleTransformer isnt helpful is the biggest problem.