You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's no use of the file system to load the project which will cause an exception as it will use the default file system.
Note that we use the custom filesystem to check if the file exists but use a different file system to load it!
Expected Behavior
Project should use the MSBuildFileSystemBase provided to it in the EvaluationContext to access the file system.
Actual Behavior
Project use the MSBuildFileSystemBase provided to it in the EvaluationContext to check if files exists but it will load the files using the default file systme.
Analysis
It's clear that ProjectRootElement or any project element does not resolve imports so it does not care about the FS.
However, the evaluator should not load the project with a path, instead it should load using a provided ProjectRootElement directly. (I.E create the project from ProjectRootElement and not from the path)
An alternative is to accept an handler to load it if it's not in the projectRootElementCache.
It is should be straight forward:
// fs: MSBuildFileSystemBasevarprojectCollection=newProjectCollection();usingvarreader=newXmlTextReader(fs.GetFileStream(pathToFile,FileMode.Open,FileAccess.Read,FileShare.None));varprojectRootElement=ProjectRootElement.Create(reader,projectCollection);// We must re-set the location so internal imports will follow the right path.// The default in this cause is the main process directory (`PWD`)projectRootElement.FullPath=pathToFile;returnProject.FromProjectRootElement(projectRootElement,newProjectOptions{LoadSettings=ProjectLoadSettings.Default,ProjectCollection=projectCollection,EvaluationContext=EvaluationContext.Create(EvaluationContext.SharingPolicy.Shared,fs),});
Versions & Configurations
Checked with 17.2 (net6). Code implies its the same form 16.9 (net5.0) and for main branch.
The text was updated successfully, but these errors were encountered:
As for use cases, we would like to implement a virtual file system that will load projects from a git commit so we can analyse the diff between 2 commits or between the working directory and any commit.
This is implemented but the missing bit is the inability to control loading of nested project within a csproj.
For example, we get to a point where the project wants to load Directory.Build.props from the csproj library.
In the working directory it's not there but in the commit it is.
The commit based file system will report Directory.Build.props is present but loading it will fail.
shlomiassaf
changed the title
MSBuildFileSystemBase is partial honoured when used to load imports
MSBuildFileSystemBase is partialy honoured when used to load imports
Sep 10, 2022
Issue Description
When creating a
Project
we can pass a custom file system implementation (MSBuildFileSystemBase
) through theEvaluationContext
The file system is used internally, among other things, to check for file existence and load references.
When checking for file existence the custom file system is indeed used:
msbuild/src/Build/Evaluation/Evaluator.cs
Line 2074 in a3b647d
However, when loading the nested referenced project:
msbuild/src/Build/Evaluation/Evaluator.cs
Lines 2191 to 2198 in a3b647d
There's no use of the file system to load the project which will cause an exception as it will use the default file system.
Note that we use the custom filesystem to check if the file exists but use a different file system to load it!
Expected Behavior
Project
should use theMSBuildFileSystemBase
provided to it in theEvaluationContext
to access the file system.Actual Behavior
Project
use theMSBuildFileSystemBase
provided to it in theEvaluationContext
to check if files exists but it will load the files using the default file systme.Analysis
It's clear that
ProjectRootElement
or any project element does not resolve imports so it does not care about the FS.However, the evaluator should not load the project with a path, instead it should load using a provided
ProjectRootElement
directly. (I.E create the project fromProjectRootElement
and not from the path)It is should be straight forward:
Versions & Configurations
Checked with 17.2 (net6). Code implies its the same form 16.9 (net5.0) and for
main
branch.The text was updated successfully, but these errors were encountered: