Skip to content

Commit

Permalink
Closes #26. +ProjectReference support without obsolete projectguid
Browse files Browse the repository at this point in the history
+Added tests
+IXProject.GetFullPath(string relative) - Makes full path using path to this project as the base.
  • Loading branch information
3F committed May 4, 2020
1 parent 838fab0 commit e07c580
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 18 deletions.
7 changes: 7 additions & 0 deletions MvsSln/Core/IXProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,13 @@ public interface IXProject
/// <returns></returns>
string GetRelativePath(string path);

/// <summary>
/// Makes full path using path to this project as the base.
/// </summary>
/// <param name="relative">any path relative to the current project.</param>
/// <returns></returns>
string GetFullPath(string relative);

/// <summary>
/// Adds 'Reference' item.
/// </summary>
Expand Down
14 changes: 13 additions & 1 deletion MvsSln/Core/ProjectReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

using System;
using System.Collections.Generic;
using System.Linq;
using net.r_eg.MvsSln.Core.SlnHandlers;
using net.r_eg.MvsSln.Extensions;
using net.r_eg.MvsSln.Projects;
Expand Down Expand Up @@ -111,9 +112,20 @@ protected void InitMap()
if(!map.ContainsKey(r.Key)) {
map[r.Key] = new HashSet<string>();
}
r.Value.ForEach(i => map[r.Key].Add(FormatGuid(i.meta["Project"].evaluated)));
r.Value.ForEach(i => ExtarctProjectGuid(i)?.E(g => map[r.Key].Add(FormatGuid(g))));
}
BuildOrder();
}

private string ExtarctProjectGuid(Item item)
{
const string _PK = "Project";
if(item.meta.ContainsKey(_PK)) return item.meta[_PK].evaluated;

return XProjects.FirstOrDefault(
p => p.ProjectItem.project.fullPath == p.GetFullPath(item.evaluatedInclude)
)?
.ProjectGuid;
}
}
}
8 changes: 8 additions & 0 deletions MvsSln/Core/XProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -467,6 +468,13 @@ public IEnumerable<PropertyItem> GetProperties()
/// <returns></returns>
public virtual string GetRelativePath(string path) => RootPath.MakeRelativePath(path);

/// <summary>
/// Makes full path using path to this project as the base.
/// </summary>
/// <param name="relative">any not null path relative to the current project.</param>
/// <returns></returns>
public string GetFullPath(string relative) => Path.GetFullPath(Path.Combine(RootPath, relative));

/// <summary>
/// Adds 'Reference' item.
/// </summary>
Expand Down
31 changes: 14 additions & 17 deletions MvsSln/Extensions/ObjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,25 @@ namespace net.r_eg.MvsSln.Extensions
public static class ObjectExtension
{
/// <summary>
/// Execute action separately from result.
/// Execute action on value in the chain separately from result.
/// </summary>
/// <typeparam name="T">The type of value that should be returned.</typeparam>
/// <param name="obj">Unspecified object.</param>
/// <param name="act">Any action that should be executed.</param>
/// <returns>Same value from selected object as T type.</returns>
public static T E<T>(this object obj, Action act)
{
act();
return (T)obj;
}
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="act"></param>
/// <returns>Input value.</returns>
public static T E<T>(this T obj, Action act) => E(obj, _=> act());

/// <summary>
/// Execute action separately from result.
/// Alias to `E&lt;object&gt;()`
/// Execute action on value in the chain separately from result.
/// </summary>
/// <param name="obj">Unspecified object.</param>
/// <param name="act">Any action that should be executed.</param>
/// <returns>Same value from selected object.</returns>
public static object E(this object obj, Action act)
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <param name="act"></param>
/// <returns>Input value.</returns>
public static T E<T>(this T obj, Action<T> act)
{
return E<object>(obj, act);
act?.Invoke(obj);
return obj;
}
}
}
3 changes: 3 additions & 0 deletions MvsSlnTest/Core/ProjectReferencesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void ActivationTheory1(string file, SlnItems items)
[InlineData(TestData.ROOT + @"ProjectDependenciesXml\noprojectguid\test.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadMinimalDefaultData)]
[InlineData(TestData.ROOT + @"ProjectDependenciesXml\noprojectguid\test.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadDefaultData)]

[InlineData(TestData.ROOT + @"ProjectDependenciesXml\onlypath\test.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadMinimalDefaultData)]
[InlineData(TestData.ROOT + @"ProjectDependenciesXml\onlypath\test.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadDefaultData)]

// Part of SlnParser.SetProjectItemsConfigs, see also tests in ProjectConfigurationPlatformsTest
[InlineData(TestData.ROOT + @"ProjectDependenciesXml\projectguid\test2.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadMinimalDefaultData)]
[InlineData(TestData.ROOT + @"ProjectDependenciesXml\projectguid\test2.sln", SlnItems.ProjectDependenciesXml | SlnItems.LoadDefaultData)]
Expand Down
36 changes: 36 additions & 0 deletions MvsSlnTest/Extensions/ObjectExtensionTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Collections.Generic;
using net.r_eg.MvsSln.Extensions;
using Xunit;

namespace MvsSlnTest.Extensions
{
public class ObjectExtensionTest
{
[Fact]
public void EReturnTest1()
{
string data = "12345 ";
Assert.Equal(data, data.E(s => s.Trim()));

void _upd(ref string input) => input = "9876";
Assert.Equal(data, data.E(s => _upd(ref s)));

const int _V = 14;
var obj = new List<int>(1) { _V };
Assert.NotEqual(_V, obj.E(v => v[0] = 8)[0]);
}

[Fact]
public void EActTest1()
{
var x = new List<int>(1) { 0 };
Assert.Equal(1, x.E(() => x[0]++)[0]);

var y = new List<int>(1) { 0 };
Assert.Equal(0, y.E(() => x[0]++)[0]);

var z = new List<int>(1) { 0 };
Assert.Equal(3, x.E(_x => _x[0]++)[0]);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectReference Include="ClassLibrary2.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>
31 changes: 31 additions & 0 deletions MvsSlnTest/resources/ProjectDependenciesXml/onlypath/test.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30011.22
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary2", "ClassLibrary2.csproj", "{64AD76CA-2C85-4039-B0B3-734CF02B2999}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1.csproj", "{6CE57BB1-4A6D-4714-B775-74A3637EC992}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{64AD76CA-2C85-4039-B0B3-734CF02B2999}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{64AD76CA-2C85-4039-B0B3-734CF02B2999}.Debug|Any CPU.Build.0 = Debug|Any CPU
{64AD76CA-2C85-4039-B0B3-734CF02B2999}.Release|Any CPU.ActiveCfg = Release|Any CPU
{64AD76CA-2C85-4039-B0B3-734CF02B2999}.Release|Any CPU.Build.0 = Release|Any CPU
{6CE57BB1-4A6D-4714-B775-74A3637EC992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CE57BB1-4A6D-4714-B775-74A3637EC992}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CE57BB1-4A6D-4714-B775-74A3637EC992}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CE57BB1-4A6D-4714-B775-74A3637EC992}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94B06088-79E0-4DE6-9D42-064E4841E9D9}
EndGlobalSection
EndGlobal

0 comments on commit e07c580

Please sign in to comment.