Merge pull request #3308 from dotnet/troy-2995
Fix dependencies type changes scenario in project model server.
This commit is contained in:
commit
c321323dff
6 changed files with 64 additions and 18 deletions
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"version": "6.0.8",
|
||||
"version": "9.0.1",
|
||||
"dependencies": {
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
"netstandard1.5": { }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "6.0.8"
|
||||
"Newtonsoft.Json": "9.0.1"
|
||||
},
|
||||
"frameworks": {
|
||||
"dnx451": { }
|
||||
"netstandard1.5": {}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,13 +9,13 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers
|
|||
{
|
||||
public static IEnumerable<DiagnosticMessage> Diagnose(
|
||||
ProjectContext context,
|
||||
IEnumerable<string> currentSearchPaths)
|
||||
IEnumerable<string> previousSearchPaths)
|
||||
{
|
||||
var result = new List<DiagnosticMessage>();
|
||||
var project = context.ProjectFile;
|
||||
var libraries = context.LibraryManager.GetLibraries();
|
||||
|
||||
var updatedSearchPath = GetUpdatedSearchPaths(currentSearchPaths, project.ResolveSearchPaths());
|
||||
var updatedSearchPath = GetUpdatedSearchPaths(previousSearchPaths, project.ResolveSearchPaths());
|
||||
var projectCandiates = GetProjectCandidates(updatedSearchPath);
|
||||
var rootDependencies = libraries.FirstOrDefault(library => string.Equals(library.Identity.Name, project.Name))
|
||||
?.Dependencies
|
||||
|
|
|
@ -24,13 +24,13 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
public IReadOnlyList<DiagnosticMessage> DependencyDiagnostics { get; set; }
|
||||
public IDictionary<string, DependencyDescription> Dependencies { get; set; }
|
||||
|
||||
public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable<string> currentSearchPaths)
|
||||
public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable<string> previousSearchPaths)
|
||||
{
|
||||
var snapshot = new ProjectContextSnapshot();
|
||||
|
||||
var allDependencyDiagnostics = new List<DiagnosticMessage>();
|
||||
allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
|
||||
allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));
|
||||
allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, previousSearchPaths));
|
||||
|
||||
var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
public static ProjectSnapshot Create(string projectDirectory,
|
||||
string configuration,
|
||||
DesignTimeWorkspace workspaceContext,
|
||||
IReadOnlyList<string> projectSearchPaths,
|
||||
IReadOnlyList<string> previousSearchPaths,
|
||||
bool clearWorkspaceContextCache)
|
||||
{
|
||||
var projectContextsCollection = workspaceContext.GetProjectContextCollection(projectDirectory, clearWorkspaceContextCache);
|
||||
|
@ -42,7 +42,7 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
foreach (var projectContext in projectContextsCollection.FrameworkOnlyContexts)
|
||||
{
|
||||
snapshot.ProjectContexts[projectContext.TargetFramework] =
|
||||
ProjectContextSnapshot.Create(projectContext, configuration, currentSearchPaths);
|
||||
ProjectContextSnapshot.Create(projectContext, configuration, previousSearchPaths);
|
||||
}
|
||||
|
||||
return snapshot;
|
||||
|
|
|
@ -257,11 +257,11 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact(Skip = "Require dotnet restore integration test")]
|
||||
[Fact]
|
||||
public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
|
||||
{
|
||||
var assets = new TestAssetsManager(Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer"));
|
||||
var projectPath = assets.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
|
||||
var assetsManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer"));
|
||||
var projectPath = assetsManager.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
|
||||
Assert.True(Directory.Exists(projectPath));
|
||||
|
||||
using (var server = new DthTestServer())
|
||||
|
@ -290,7 +290,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
// Overwrite the global.json to remove search path to ext
|
||||
File.WriteAllText(
|
||||
Path.Combine(projectPath, "home", GlobalSettings.FileName),
|
||||
JsonConvert.SerializeObject(new { project = new string[] { "src" } }));
|
||||
JsonConvert.SerializeObject(new { projects = new string[] { "src" } }));
|
||||
|
||||
client.SendPayload(testProject, "RefreshDependencies");
|
||||
|
||||
|
@ -302,17 +302,63 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
|
||||
client.DrainTillFirst("Dependencies")
|
||||
.RetrieveDependency("Newtonsoft.Json")
|
||||
.AssertProperty("Type", "")
|
||||
.AssertProperty("Resolved", false)
|
||||
.AssertProperty("Type", "Project")
|
||||
.RetrievePropertyAs<JArray>("Errors")
|
||||
.AssertJArrayCount(1)
|
||||
.RetrieveArraryElementAs<JObject>(0)
|
||||
.AssertProperty("ErrorCode", "NU1010");
|
||||
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
|
||||
|
||||
client.DrainTillFirst("DependencyDiagnostics")
|
||||
.RetrieveDependencyDiagnosticsCollection()
|
||||
.RetrieveDependencyDiagnosticsErrorAt<JObject>(0)
|
||||
.AssertProperty("ErrorCode", "NU1010");
|
||||
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
|
||||
|
||||
var restoreCommand = new RestoreCommand();
|
||||
restoreCommand.WorkingDirectory = projectPath;
|
||||
restoreCommand.Execute().Should().Pass();
|
||||
|
||||
client.SendPayload(testProject, "RefreshDependencies");
|
||||
|
||||
client.DrainTillFirst("Dependencies")
|
||||
.RetrieveDependency("Newtonsoft.Json")
|
||||
.AssertProperty("Resolved", true)
|
||||
.AssertProperty("Type", "Package")
|
||||
.RetrievePropertyAs<JArray>("Errors")
|
||||
.AssertJArrayCount(0);
|
||||
|
||||
client.DrainTillFirst("DependencyDiagnostics")
|
||||
.RetrievePayloadAs<JObject>()
|
||||
.AssertProperty<JArray>("Errors", array => array.Count == 0)
|
||||
.AssertProperty<JArray>("Warnings", array => array.Count == 0);
|
||||
|
||||
// Overwrite the global.json to add search path to ext back
|
||||
File.WriteAllText(
|
||||
Path.Combine(projectPath, "home", GlobalSettings.FileName),
|
||||
JsonConvert.SerializeObject(new { projects = new string[] { "src", "../ext" } }));
|
||||
|
||||
client.SendPayload(testProject, "RefreshDependencies");
|
||||
|
||||
client.DrainTillFirst("ProjectInformation")
|
||||
.RetrievePayloadAs<JObject>()
|
||||
.RetrievePropertyAs<JArray>("ProjectSearchPaths")
|
||||
.AssertJArrayCount(2)
|
||||
.AssertJArrayElement(0, Path.Combine(projectPath, "home", "src"))
|
||||
.AssertJArrayElement(1, Path.Combine(projectPath, "ext"));
|
||||
|
||||
client.DrainTillFirst("Dependencies")
|
||||
.RetrieveDependency("Newtonsoft.Json")
|
||||
.AssertProperty("Resolved", false)
|
||||
.AssertProperty("Type", "Package")
|
||||
.RetrievePropertyAs<JArray>("Errors")
|
||||
.AssertJArrayCount(1)
|
||||
.RetrieveArraryElementAs<JObject>(0)
|
||||
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
|
||||
|
||||
client.DrainTillFirst("DependencyDiagnostics")
|
||||
.RetrieveDependencyDiagnosticsCollection()
|
||||
.RetrieveDependencyDiagnosticsErrorAt<JObject>(0)
|
||||
.AssertProperty("ErrorCode", ErrorCodes.NU1010);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue