diff --git a/MvsSln/Core/IXProject.cs b/MvsSln/Core/IXProject.cs index 14856ef..882a17e 100644 --- a/MvsSln/Core/IXProject.cs +++ b/MvsSln/Core/IXProject.cs @@ -252,6 +252,13 @@ public interface IXProject /// string GetRelativePath(string path); + /// + /// Makes full path using path to this project as the base. + /// + /// any path relative to the current project. + /// + string GetFullPath(string relative); + /// /// Adds 'Reference' item. /// diff --git a/MvsSln/Core/ProjectReferences.cs b/MvsSln/Core/ProjectReferences.cs index b64f011..6467491 100644 --- a/MvsSln/Core/ProjectReferences.cs +++ b/MvsSln/Core/ProjectReferences.cs @@ -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; @@ -111,9 +112,20 @@ protected void InitMap() if(!map.ContainsKey(r.Key)) { map[r.Key] = new HashSet(); } - 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; + } } } \ No newline at end of file diff --git a/MvsSln/Core/XProject.cs b/MvsSln/Core/XProject.cs index ad9ab14..707ab40 100644 --- a/MvsSln/Core/XProject.cs +++ b/MvsSln/Core/XProject.cs @@ -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; @@ -467,6 +468,13 @@ public IEnumerable GetProperties() /// public virtual string GetRelativePath(string path) => RootPath.MakeRelativePath(path); + /// + /// Makes full path using path to this project as the base. + /// + /// any not null path relative to the current project. + /// + public string GetFullPath(string relative) => Path.GetFullPath(Path.Combine(RootPath, relative)); + /// /// Adds 'Reference' item. /// diff --git a/MvsSln/Extensions/ObjectExtension.cs b/MvsSln/Extensions/ObjectExtension.cs index 173b41b..a2767bc 100644 --- a/MvsSln/Extensions/ObjectExtension.cs +++ b/MvsSln/Extensions/ObjectExtension.cs @@ -30,28 +30,25 @@ namespace net.r_eg.MvsSln.Extensions public static class ObjectExtension { /// - /// Execute action separately from result. + /// Execute action on value in the chain separately from result. /// - /// The type of value that should be returned. - /// Unspecified object. - /// Any action that should be executed. - /// Same value from selected object as T type. - public static T E(this object obj, Action act) - { - act(); - return (T)obj; - } + /// + /// + /// + /// Input value. + public static T E(this T obj, Action act) => E(obj, _=> act()); /// - /// Execute action separately from result. - /// Alias to `E<object>()` + /// Execute action on value in the chain separately from result. /// - /// Unspecified object. - /// Any action that should be executed. - /// Same value from selected object. - public static object E(this object obj, Action act) + /// + /// + /// + /// Input value. + public static T E(this T obj, Action act) { - return E(obj, act); + act?.Invoke(obj); + return obj; } } } \ No newline at end of file diff --git a/MvsSlnTest/Core/ProjectReferencesTest.cs b/MvsSlnTest/Core/ProjectReferencesTest.cs index aefd92f..a5a4455 100644 --- a/MvsSlnTest/Core/ProjectReferencesTest.cs +++ b/MvsSlnTest/Core/ProjectReferencesTest.cs @@ -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)] diff --git a/MvsSlnTest/Extensions/ObjectExtensionTest.cs b/MvsSlnTest/Extensions/ObjectExtensionTest.cs new file mode 100644 index 0000000..90a9097 --- /dev/null +++ b/MvsSlnTest/Extensions/ObjectExtensionTest.cs @@ -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(1) { _V }; + Assert.NotEqual(_V, obj.E(v => v[0] = 8)[0]); + } + + [Fact] + public void EActTest1() + { + var x = new List(1) { 0 }; + Assert.Equal(1, x.E(() => x[0]++)[0]); + + var y = new List(1) { 0 }; + Assert.Equal(0, y.E(() => x[0]++)[0]); + + var z = new List(1) { 0 }; + Assert.Equal(3, x.E(_x => _x[0]++)[0]); + } + } +} diff --git a/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary1.csproj b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary1.csproj new file mode 100644 index 0000000..6c1b3dc --- /dev/null +++ b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary1.csproj @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary2.csproj b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary2.csproj new file mode 100644 index 0000000..4c1e193 --- /dev/null +++ b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/ClassLibrary2.csproj @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/test.sln b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/test.sln new file mode 100644 index 0000000..f2799b2 --- /dev/null +++ b/MvsSlnTest/resources/ProjectDependenciesXml/onlypath/test.sln @@ -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