提交 42b38bf3 编写于 作者: V Vasily Kirichenko 提交者: Don Syme

Fix "The path is not of a legal form" during loading VFT solution (#3007)

* check if a referenced assembly exists before adding it into ProjectContext's metadata references

* check path correctness
上级 53f1103e
...@@ -264,6 +264,9 @@ and ...@@ -264,6 +264,9 @@ and
project.Disconnect() project.Disconnect()
| _ -> () | _ -> ()
let invalidPathChars = set (Path.GetInvalidPathChars())
let isPathWellFormed (path: string) = not (String.IsNullOrWhiteSpace path) && path |> Seq.forall (fun c -> not (Set.contains c invalidPathChars))
override this.Initialize() = override this.Initialize() =
base.Initialize() base.Initialize()
...@@ -304,9 +307,11 @@ and ...@@ -304,9 +307,11 @@ and
/// Sync the information for the project /// Sync the information for the project
member this.SyncProject(project: AbstractProject, projectContext: IWorkspaceProjectContext, site: IProjectSite, workspace, forceUpdate) = member this.SyncProject(project: AbstractProject, projectContext: IWorkspaceProjectContext, site: IProjectSite, workspace, forceUpdate) =
let hashSetIgnoreCase x = new HashSet<string>(x, StringComparer.OrdinalIgnoreCase) let wellFormedFilePathSetIgnoreCase (paths: seq<string>) =
let updatedFiles = site.SourceFilesOnDisk() |> hashSetIgnoreCase HashSet(paths |> Seq.filter isPathWellFormed, StringComparer.OrdinalIgnoreCase)
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map(fun file -> file.FilePath) |> hashSetIgnoreCase
let updatedFiles = site.SourceFilesOnDisk() |> wellFormedFilePathSetIgnoreCase
let workspaceFiles = project.GetCurrentDocuments() |> Seq.map (fun file -> file.FilePath) |> wellFormedFilePathSetIgnoreCase
let mutable updated = forceUpdate let mutable updated = forceUpdate
...@@ -314,17 +319,19 @@ and ...@@ -314,17 +319,19 @@ and
if not(workspaceFiles.Contains(file)) then if not(workspaceFiles.Contains(file)) then
projectContext.AddSourceFile(file) projectContext.AddSourceFile(file)
updated <- true updated <- true
for file in workspaceFiles do for file in workspaceFiles do
if not(updatedFiles.Contains(file)) then if not(updatedFiles.Contains(file)) then
projectContext.RemoveSourceFile(file) projectContext.RemoveSourceFile(file)
updated <- true updated <- true
let updatedRefs = site.AssemblyReferences() |> hashSetIgnoreCase let updatedRefs = site.AssemblyReferences() |> wellFormedFilePathSetIgnoreCase
let workspaceRefs = project.GetCurrentMetadataReferences() |> Seq.map(fun ref -> ref.FilePath) |> hashSetIgnoreCase let workspaceRefs = project.GetCurrentMetadataReferences() |> Seq.map (fun ref -> ref.FilePath) |> wellFormedFilePathSetIgnoreCase
for ref in updatedRefs do for ref in updatedRefs do
if not(workspaceRefs.Contains(ref)) then if not(workspaceRefs.Contains(ref)) then
projectContext.AddMetadataReference(ref, MetadataReferenceProperties.Assembly) projectContext.AddMetadataReference(ref, MetadataReferenceProperties.Assembly)
for ref in workspaceRefs do for ref in workspaceRefs do
if not(updatedRefs.Contains(ref)) then if not(updatedRefs.Contains(ref)) then
projectContext.RemoveMetadataReference(ref) projectContext.RemoveMetadataReference(ref)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册