diff --git a/src/NuGetReferenceSwitcher.Presentation/Models/FromNuGetToProjectTransformation.cs b/src/NuGetReferenceSwitcher.Presentation/Models/FromNuGetToProjectTransformation.cs
index d6ef538..d26efdf 100644
--- a/src/NuGetReferenceSwitcher.Presentation/Models/FromNuGetToProjectTransformation.cs
+++ b/src/NuGetReferenceSwitcher.Presentation/Models/FromNuGetToProjectTransformation.cs
@@ -23,7 +23,9 @@ public enum NuGetToProjectMode
public class FromNuGetToProjectTransformation : ObservableObject
{
private string _toProjectPath;
+ private string _toTestProjectPath;
private ProjectModel _toProject;
+ private ProjectModel _toTestProject;
/// Initializes a new instance of the class.
/// The projects.
@@ -44,6 +46,12 @@ public FromNuGetToProjectTransformation(List projects, ReferenceMo
ToProjectPath = swi.FromProjectPath;
else
ToProject = targetProject;
+
+ var targetTestProject = projects.FirstOrDefault(p => p.Path == swi.FromTestProjectPath);
+ if (targetTestProject == null)
+ ToTestProjectPath = swi.FromTestProjectPath;
+ else
+ ToTestProject = targetProject;
}
else
SelectedMode = NuGetToProjectMode.Deactivated;
@@ -96,6 +104,36 @@ public ProjectModel ToProject
}
}
+ public ProjectModel ToTestProject
+ {
+ get { return _toTestProject; }
+ set
+ {
+ if (Set(ref _toTestProject, value))
+ {
+ if (_toTestProject == null)
+ SelectedMode = NuGetToProjectMode.ProjectPath;
+ else
+ SelectedMode = NuGetToProjectMode.Project;
+ }
+ }
+ }
+
+ public string ToTestProjectPath
+ {
+ get { return _toTestProjectPath; }
+ set
+ {
+ if (Set(ref _toTestProjectPath, value))
+ {
+ if (_toTestProjectPath == null)
+ SelectedMode = NuGetToProjectMode.Project;
+ else
+ SelectedMode = NuGetToProjectMode.ProjectPath;
+ }
+ }
+ }
+
/// Gets the evaluated to project path.
public string EvaluatedToProjectPath
{
diff --git a/src/NuGetReferenceSwitcher.Presentation/Models/FromProjectToNuGetTransformation.cs b/src/NuGetReferenceSwitcher.Presentation/Models/FromProjectToNuGetTransformation.cs
index e223bfc..e63c71c 100644
--- a/src/NuGetReferenceSwitcher.Presentation/Models/FromProjectToNuGetTransformation.cs
+++ b/src/NuGetReferenceSwitcher.Presentation/Models/FromProjectToNuGetTransformation.cs
@@ -18,5 +18,11 @@ public class FromProjectToNuGetTransformation
/// Gets or sets the NuGet assembly path name to switch to.
public string ToAssemblyPath { get; set; }
+
+ /// Gets or sets the test project name.
+ public string FromTestProjectName { get; set; }
+
+ /// Gets or sets the test project path.
+ public string FromTestProjectPath { get; set; }
}
}
\ No newline at end of file
diff --git a/src/NuGetReferenceSwitcher.Presentation/Models/ProjectModel.cs b/src/NuGetReferenceSwitcher.Presentation/Models/ProjectModel.cs
index 40e7d48..8ddbc7a 100644
--- a/src/NuGetReferenceSwitcher.Presentation/Models/ProjectModel.cs
+++ b/src/NuGetReferenceSwitcher.Presentation/Models/ProjectModel.cs
@@ -31,7 +31,7 @@ public ProjectModel(VSProject project, DTE application)
{
_vsProject = project;
- Name = project.Project.Name;
+ Name = project.Project.Name;
SolutionFile = new FileInfo(application.Solution.FileName);
LoadReferences();
}
@@ -56,7 +56,7 @@ public string PreviousConfigurationPath
{
get { return GetConfigurationPath(".previous.nugetreferenceswitcher"); }
}
-
+
/// Gets the current project reference to NuGet reference transformations.
public List CurrentToNuGetTransformations
{
@@ -78,7 +78,7 @@ public string Path
/// Deletes the previous configuration file and renames the current
/// configuration file to the path of the previous configuration file.
public void DeleteConfigurationFile()
- {
+ {
if (File.Exists(CurrentConfigurationPath))
{
if (File.Exists(PreviousConfigurationPath))
@@ -98,11 +98,15 @@ public void AddProjectReference(ProjectModel project)
/// Saves the project.
public void Save()
{
- // TODO: This may lock up the UI => check and fix
- Dispatcher.CurrentDispatcher.InvokeAsync(() =>
+ // The Dispatcher was not working, plus not all Project items were saved. This work fines (after also saving the solution)
+ // No need to save the solution manually afterward.
+ _vsProject.Project.Save();
+ for (int j = 1; j <= _vsProject.Project.ProjectItems.Count; j++)
{
- _vsProject.Project.Save();
- });
+ var item = _vsProject.Project.ProjectItems.Item(j);
+ if (!item.Saved)
+ item.Save();
+ }
}
/// Adds an assembly reference to the project.
@@ -118,7 +122,7 @@ public bool AddReference(string assemblyPath)
return true;
}
- return false;
+ return false;
}
/// Removes the project from the solution.
@@ -144,15 +148,18 @@ private List LoadTransformationsFromFile(strin
{
var lines = File.ReadAllLines(configurationPath)
.Select(l => l.Split('\t'))
- .Where(l => l.Length == 3).ToArray();
+ .Where(l => l.Length == 5).ToArray();
+
-
foreach (var line in lines)
- list.Add(new FromProjectToNuGetTransformation {
+ list.Add(new FromProjectToNuGetTransformation
+ {
FromProjectName = line[0],
FromProjectPath = PathUtilities.MakeAbsolute(line[1], configurationPath),
- ToAssemblyPath = PathUtilities.MakeAbsolute(line[2], configurationPath)
+ ToAssemblyPath = PathUtilities.MakeAbsolute(line[2], configurationPath),
+ FromTestProjectName = line[3],
+ FromTestProjectPath = PathUtilities.MakeAbsolute(line[4], configurationPath),
});
}
return list;
diff --git a/src/NuGetReferenceSwitcher.Presentation/ViewModels/MainDialogModel.cs b/src/NuGetReferenceSwitcher.Presentation/ViewModels/MainDialogModel.cs
index 41a9a7a..51a4f1b 100644
--- a/src/NuGetReferenceSwitcher.Presentation/ViewModels/MainDialogModel.cs
+++ b/src/NuGetReferenceSwitcher.Presentation/ViewModels/MainDialogModel.cs
@@ -130,11 +130,18 @@ await RunTaskAsync(token => Task.Run(() =>
project.AddProjectReference(assemblyToProjectSwitch.ToProject);
nuGetReferenceTransformationsForProject +=
- assemblyToProjectSwitch.ToProject.Name + "\t" +
+ assemblyToProjectSwitch.ToProject.Name +
+ "\t" +
PathUtilities.MakeRelative(assemblyToProjectSwitch.ToProject.Path,
- project.CurrentConfigurationPath) + "\t" +
+ project.CurrentConfigurationPath) +
+ "\t" +
PathUtilities.MakeRelative(fromAssemblyPath, project.CurrentConfigurationPath) +
- "\n";
+ "\t" +
+ assemblyToProjectSwitch.ToTestProject.Name +
+ "\t" +
+ PathUtilities.MakeRelative(assemblyToProjectSwitch.ToTestProject.Path,
+ project.CurrentConfigurationPath) +
+ "\n";
}
else
{
@@ -153,9 +160,13 @@ await RunTaskAsync(token => Task.Run(() =>
File.AppendAllText(project.CurrentConfigurationPath, nuGetReferenceTransformationsForProject);
}
}
+ if (!Application.Solution.Saved)
+ Application.Solution.SaveAs(Application.Solution.FullName);
}, token));
}
+
+
/// Handles an exception which occured in the method.
/// The exception.
public override void HandleException(Exception exception)
@@ -186,7 +197,7 @@ await RunTaskAsync(token => Task.Run(() =>
{
MessageBox.Show("The project '" + transformation.ToAssemblyPath + "' could not be added. " +
"\nSkipped.", "Could not add project", MessageBoxButton.OK, MessageBoxImage.Error);
- }
+ }
}
}
@@ -197,6 +208,8 @@ await RunTaskAsync(token => Task.Run(() =>
}
RemoveProjectsFromSolution(projectsToRemove);
+ if (!Application.Solution.Saved)
+ Application.Solution.SaveAs(Application.Solution.FullName);
}, token));
}
@@ -245,15 +258,29 @@ private void AddProjectToSolutionIfNeeded(FromNuGetToProjectTransformation fromN
}
else
MessageBox.Show("The project '" + fromNuGetToProjectTransformation.ToProjectPath + "' could not be found. (ignored)", "Project not found", MessageBoxButton.OK, MessageBoxImage.Stop);
+ if (!string.IsNullOrEmpty(fromNuGetToProjectTransformation.ToTestProjectPath) && File.Exists(fromNuGetToProjectTransformation.ToTestProjectPath))
+ {
+ var project = Application.Solution.AddFromFile(fromNuGetToProjectTransformation.ToTestProjectPath);
+ var myProject = new ProjectModel((VSProject)project.Object, Application);
+ fromNuGetToProjectTransformation.ToTestProject = myProject;
+ }
}
}
private List GetCurrentProjectsToRemove()
{
- return Projects
+ var pjToRemove = new List();
+ var projectsToRemove = Projects
.SelectMany(p => p.CurrentToNuGetTransformations.Select(s => s.FromProjectName))
.Select(name => Projects.SingleOrDefault(p => p.Name == name))
.ToList();
+ pjToRemove.AddRange(projectsToRemove);
+ var testProjectsToRemove = Projects
+ .SelectMany(p => p.CurrentToNuGetTransformations.Select(s => s.FromTestProjectName))
+ .Select(name => Projects.SingleOrDefault(p => p.Name == name))
+ .ToList();
+ pjToRemove.AddRange(testProjectsToRemove);
+ return pjToRemove;
}
private void RemoveProjectsFromSolution(List projectsToDelete)
diff --git a/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml b/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml
index fbb3307..c5e39d9 100644
--- a/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml
+++ b/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml
@@ -68,6 +68,13 @@
SelectedItem="{Binding ToProject, Mode=TwoWay}"
DisplayMemberPath="Name" />
+
+
+
+
+
+
diff --git a/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml.cs b/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml.cs
index f415c56..cd5e963 100644
--- a/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml.cs
+++ b/src/NuGetReferenceSwitcher.Presentation/Views/MainDialog.xaml.cs
@@ -102,5 +102,24 @@ private void OnSelectProjectFile(object sender, RoutedEventArgs e)
if (_dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
fntpSwitch.ToProjectPath = _dlg.FileName;
}
+
+ private void OnSelectTestProjectFile(object sender, RoutedEventArgs e)
+ {
+ var fntpSwitch = (FromNuGetToProjectTransformation)((Button)sender).Tag;
+ if (_dlg == null)
+ {
+ _dlg = new OpenFileDialog();
+ _dlg.Filter = "CSharp Projects (*.csproj)|*.csproj|VB.NET Projects (*.vbproj)|*.vbproj";
+
+ // switch to VB if any VB project is already referenced
+ if (Model.Transformations.Any(t => t.ToTestProjectPath != null && t.ToTestProjectPath.EndsWith(".vbproj", System.StringComparison.OrdinalIgnoreCase)))
+ _dlg.FilterIndex = 2;
+ }
+
+ _dlg.Title = string.Format("Select Project for '{0}'", fntpSwitch.FromAssemblyName);
+
+ if (_dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+ fntpSwitch.ToTestProjectPath = _dlg.FileName;
+ }
}
}