-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow loading of projects that are missing imports. (#206)
## The Problem To load project files with missing Imports, we need to supply one or two ProjectLoadSettings flags to everywhere a project file could be parsed. These flags are `ProjectLoadSettings.IgnoreMissingImports` and `ProjectLoadSettings.IgnoreInvalidImports`. Ideally we need to find everywhere that a project would be loaded (so anywhere `Project(...)` or `ProjectInstance(...)` occur) and make sure these flags are applied. ## Phase 1 - protecting the main constructors For our purposes there are two main places that `ProjectLoadSettings` can be specified * when the `Project` constructor is called in the `WorkspaceLoader` * as part of the `buildParameters` for the `WorkspaceLoaderViaProjectGraph` Applying these changes to the existing call-sites was fairly easy - there were something like 6 places that Projects/Project Instances were directly created. Here we come to our first hurdle - the `ProjectInstance` constructor doesn't surface `ProjectLoadSettings` in any way. So step one was to turn any sort of `ProjectInstance` creation into a two-phase operation: * create the `Project` with appropriate load settings * create the `ProjectInstance` from that `Project` This got us most of the way through the tests. ## Phase 2 - TFM detection With one hurdle - the way we detected the TFM for a project involved loading a `ProjectInstance` directly and reading properties from it, and this turned out to be error prone because of the reasons mentioned above - `ProjectInstance` doesn't have `ProjectLoadSettings`. So we needed to create a `Project` to get the `ProjectInstance` from, as described above. ## Phase 3 - ProjectCollection management The above fix worked for more tests, but others still failed because the 'same project' was being created (and implicitly assigned to the global `ProjectCollection`) multiple times - a big no-no for `ProjectCollections`. So this required two changes: * create and manage a `ProjectCollection` as a 'container' for a given call to `LoadProjects` - this allows us to cache the evaluations and design-time builds over the course of a single call to `LoadProjects` while also not cluttering/clobbering the global default `ProjectCollection` * implement a function that safely retrieves an existing `Project` from the `ProjectCollection` if one exists for the same project path + global properties - if not, a new `Project` is created. With these two changes, all the tests (including the new tests) became green.
- Loading branch information
Showing
7 changed files
with
289 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[<EntryPoint>] | ||
let main args = | ||
1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<RootNamespace>missing_import</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<Import Project="$(MSBuildExtensionsPath)Foo\Foo.targets" /> | ||
|
||
</Project> |