コード例 #1
0
ファイル: PackagesConfigLocator.cs プロジェクト: 3F/MvsSln
        private static IEnumerable <string> FindSolutionConfigs(ISlnResult sln, SlnItems items)
        {
            string dfile = Path.GetFullPath(Path.Combine(sln.SolutionDir, PackagesConfig.FNAME));

            if (File.Exists(dfile))
            {
                yield return(dfile);
            }

            if (sln.SolutionFolders != null)
            {
                foreach (RawText file in sln.SolutionFolders.SelectMany(f => f.items))
                {
                    if (!file.trimmed.EndsWith(PackagesConfig.FNAME))
                    {
                        continue;
                    }

                    string input = Path.GetFullPath(Path.Combine(sln.SolutionDir, file));
                    if (File.Exists(input))
                    {
                        yield return(input);
                    }
                }
            }
        }
コード例 #2
0
 /// <param name="type">Allowed type of operations.</param>
 /// <param name="raw">Solution raw data.</param>
 /// <param name="projects">Dictionary of raw xml projects by Guid.</param>
 public Sln(SlnItems type, RawText raw, IDictionary <string, RawText> projects)
 {
     parser.RawXmlProjects = projects;
     using (var reader = new StreamReader(raw.data.GetStream(raw.encoding), raw.encoding)) {
         Result = parser.Parse(reader, type);
     }
 }
コード例 #3
0
        /// <summary>
        /// To parse data from used stream.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="type">Allowed type of operations.</param>
        /// <returns></returns>
        public ISlnResult Parse(StreamReader reader, SlnItems type)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader), MsgResource.ValueNoEmptyOrNull);
            }

            string sln = (reader.BaseStream is FileStream) ? ((FileStream)reader.BaseStream).Name : MEM_FILE;

            var data = new SlnResult()
            {
                SolutionDir = sln.GetDirectoryFromFile(),
                ResultType  = type,
            };

            Process(new Svc(reader, data));

            if (data.SolutionConfigs != null)
            {
                data.DefaultConfig = new ConfigItem(
                    ExtractDefaultConfiguration(data.SolutionConfigs),
                    ExtractDefaultPlatform(data.SolutionConfigs)
                    );
            }

            data.Properties = GlobalProperties(
                sln,
                data.DefaultConfig?.Configuration,
                data.DefaultConfig?.Platform
                );

            Aliases(data);

            if ((type & SlnItems.Env) == SlnItems.Env)
            {
                data.Env = new IsolatedEnv(data, RawXmlProjects);
                if ((type & SlnItems.EnvWithMinimalProjects) == SlnItems.EnvWithMinimalProjects)
                {
                    data.Env.LoadMinimalProjects();
                }
                if ((type & SlnItems.EnvWithProjects) == SlnItems.EnvWithProjects)
                {
                    data.Env.LoadProjects();
                }
            }

            if ((type & SlnItems.ProjectDependenciesXml) == SlnItems.ProjectDependenciesXml)
            {
                if (data.Env?.Projects != null)
                {
                    // The following class provides additional features for project references in ISlnPDManager manner,
                    // But we'll just activate references for existing ProjectDependencies (shallow copy)
                    // just to eliminate miscellaneous units between VS and msbuild world: https://github.com/3F/MvsSln/issues/25
                    new ProjectReferences(data.ProjectDependencies, data.Env.Projects);
                }
            }

            return(data);
        }
コード例 #4
0
 public void SlnItemsTest3(SlnItems items)
 {
     //report https://github.com/3F/MvsSln/issues/25#issuecomment-743840401
     using (var sln = new Sln(items, string.Empty))
     {
         Assert.Null(sln.Result.ProjectDependencies);
     }
 }
コード例 #5
0
        /// <summary>
        /// Parse of selected .sln file.
        /// </summary>
        /// <param name="sln">Solution file</param>
        /// <param name="type">Allowed type of operations.</param>
        /// <returns></returns>
        public ISlnResult Parse(string sln, SlnItems type)
        {
            if (string.IsNullOrWhiteSpace(sln))
            {
                throw new ArgumentNullException(nameof(sln), MsgResource.ValueNoEmptyOrNull);
            }

            using var reader = new StreamReader(sln, encoding);
            return(Parse(reader, type));
        }
コード例 #6
0
 public void ProjectGuidTheory1(string file, SlnItems items)
 {
     using (var sln = new Sln(file, items))
     {
         foreach (var pcfg in sln.Result.ProjectItemsConfigs)
         {
             Assert.NotNull(pcfg.project.pGuid);
         }
     }
 }
コード例 #7
0
        public void FindTest1(string file, SlnItems items)
        {
            using Sln sln = new(file, items);
            IEnumerable <string> pkgs = PackagesConfigLocator.FindConfigs(sln.Result, sln.Result.ResultType);

            Assert.Equal(sln.Result.PackagesConfigs.Count(), pkgs.Count());

            int idx = 0;

            foreach (var config in sln.Result.PackagesConfigs)
            {
                Assert.Equal(config.File, pkgs.ElementAt(idx++));
            }
        }
コード例 #8
0
        /// <summary>
        /// To parse data from used stream.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="type">Allowed type of operations.</param>
        /// <returns></returns>
        public ISlnResult Parse(StreamReader reader, SlnItems type)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader), MsgResource.ValueNoEmptyOrNull);
            }

            string sln = (reader.BaseStream is FileStream) ? ((FileStream)reader.BaseStream).Name : MEM_FILE;

            var data = new SlnResult()
            {
                SolutionDir = sln.GetDirectoryFromFile(),
                ResultType  = type,
            };

            Process(new Svc(reader, data));

            if (data.SolutionConfigs != null)
            {
                data.DefaultConfig = new ConfigItem(
                    ExtractDefaultConfiguration(data.SolutionConfigs),
                    ExtractDefaultPlatform(data.SolutionConfigs)
                    );
            }

            data.Properties = GlobalProperties(
                sln,
                data.DefaultConfig?.Configuration,
                data.DefaultConfig?.Platform
                );

            Aliases(data);

            if ((type & SlnItems.Env) == SlnItems.Env)
            {
                data.Env = new IsolatedEnv(data, RawXmlProjects);
                if ((type & SlnItems.EnvWithMinimalProjects) == SlnItems.EnvWithMinimalProjects)
                {
                    data.Env.LoadMinimalProjects();
                }
                if ((type & SlnItems.EnvWithProjects) == SlnItems.EnvWithProjects)
                {
                    data.Env.LoadProjects();
                }
            }
            return(data);
        }
コード例 #9
0
ファイル: ProjectReferencesTest.cs プロジェクト: ymf1/MvsSln
        public void ActivationTheory1(string file, SlnItems items)
        {
            using (var sln = new Sln(file, items))
            {
                var dep = sln.Result.ProjectDependencies.Dependencies;
                Assert.Equal(2, dep.Count);
                Assert.Empty(dep["{64AD76CA-2C85-4039-B0B3-734CF02B2999}"]);
                Assert.Empty(dep["{6CE57BB1-4A6D-4714-B775-74A3637EC992}"]);

                if ((items & SlnItems.ProjectDependenciesXml) == SlnItems.ProjectDependenciesXml)
                {
                    Assert.Empty(sln.Result.Env.Projects);
                }
                else
                {
                    Assert.Null(sln.Result.Env);
                }
            }
        }
コード例 #10
0
        public void SlnPackagesConfigTest1(string input, SlnItems items)
        {
            using Sln l = new(input, items);

            Assert.Single(l.Result.PackagesConfigs);
            PackagesConfig pkg = l.Result.PackagesConfigs.First();

            Assert.Equal(2, pkg.Packages.Count());

            IPackageInfo info = pkg.GetPackage("LX4Cnh");

            Assert.Equal("1.1.0", info.Version);
            Assert.Equal("net472", info.MetaTFM);

            IPackageInfo info2 = pkg.GetPackage("vsSolutionBuildEvent");

            Assert.Equal("1.14.1.1", info2.Version);
            Assert.Equal("vsSBE", info2.MetaOutput);
        }
コード例 #11
0
ファイル: ProjectReferencesTest.cs プロジェクト: ymf1/MvsSln
        public void ActivationTheory2(string file, SlnItems items)
        {
            const string _P1 = "{64AD76CA-2C85-4039-B0B3-734CF02B2999}";
            const string _P2 = "{6CE57BB1-4A6D-4714-B775-74A3637EC992}";

            using (var sln = new Sln(file, items))
            {
                Assert.NotNull(sln.Result.Env);
                Assert.NotEmpty(sln.Result.Env.Projects);

                Assert.Equal(sln.Result.ProjectDependencies.Projects.Count, sln.Result.ProjectDependencies.Dependencies.Count);

                var dep = sln.Result.ProjectDependencies.Dependencies;
                Assert.Equal(2, dep.Count);
                Assert.Empty(dep[_P1]);
                Assert.Single(dep[_P2]);

                Assert.Equal(_P1, dep[_P2].First());
            }
        }
コード例 #12
0
ファイル: PackagesConfigLocator.cs プロジェクト: 3F/MvsSln
        private static IEnumerable <string> FindAllConfigs(ISlnResult sln, SlnItems items)
        {
            if (sln == null)
            {
                throw new ArgumentNullException(nameof(sln));
            }

            if (items.HasFlag(SlnItems.PackagesConfigSolution))
            {
                foreach (var config in FindSolutionConfigs(sln, items))
                {
                    yield return(config);
                }
            }

            if (items.HasFlag(SlnItems.PackagesConfigLegacy))
            {
                foreach (var config in FindLegacyConfigs(sln))
                {
                    yield return(config);
                }
            }
        }
コード例 #13
0
ファイル: SlnItemsTest.cs プロジェクト: 3F/MvsSln
        public void AllItemsTest2(SlnItems input, params SlnItems[] ignoring)
        {
            foreach (var item in Enum.GetValues(typeof(SlnItems)))
            {
                SlnItems v = (SlnItems)item;
                if (!input.HasFlag(v))
                {
                    bool failed = true;
                    foreach (var ignore in ignoring)
                    {
                        if (v.HasFlag(ignore))
                        {
                            failed = false;
                            break;
                        }
                    }

                    if (failed)
                    {
                        Assert.False(true, $"`{input}` is not completed. Found `{v}`");
                    }
                }
            }
        }
コード例 #14
0
 /// <param name="type">Allowed type of operations.</param>
 /// <param name="raw">Raw data inside string.</param>
 public Sln(SlnItems type, string raw)
     : this(type, raw, Encoding.UTF8)
 {
 }
コード例 #15
0
 /// <param name="type">Allowed type of operations.</param>
 /// <param name="raw">Raw data inside string.</param>
 /// <param name="Enc">Encoding of raw data.</param>
 public Sln(SlnItems type, string raw, Encoding Enc)
     : this(type, new RawText() { data = raw, encoding = Enc }, null)
 {
 }
コード例 #16
0
 /// <param name="reader"></param>
 /// <param name="type">Allowed type of operations.</param>
 public Sln(StreamReader reader, SlnItems type)
 {
     Result = parser.Parse(reader, type);
 }
コード例 #17
0
 /// <param name="file">Solution file</param>
 /// <param name="type">Allowed type of operations.</param>
 public Sln(string file, SlnItems type)
 {
     Result = parser.Parse(file, type);
 }
コード例 #18
0
ファイル: XProjectEnv.cs プロジェクト: 3F/MvsSln
        public void CorrectProjectInstnacesTest(string configuration, string platform, SlnItems opt)
        {
            using Sln sln = new(TestData.PathTo(@"XProjectEnv\projectInstnaces\ClassLibrary1.sln"), opt);
            ISlnResult l = sln.Result;

            ConfigItem  input = new(configuration, platform);
            ProjectItem prj   = l.ProjectItems.FirstOrDefault();

            IXProject xp = l.Env.XProjectByFile
                           (
                prj.fullPath,
                input,
                new Dictionary <string, string>()
            {
                { PropertyNames.CONFIG, configuration }, { PropertyNames.PLATFORM, platform }
            }
                           );

            Assert.True(input.Equals(xp.ProjectItem.projectConfig));

            Assert.Equal
            (
                input,
                new(xp.Project.GlobalProperties[PropertyNames.CONFIG], xp.Project.GlobalProperties[PropertyNames.PLATFORM])
            );

            var p = l.Env.GetOrLoadProject
                    (
                l.ProjectItems.FirstOrDefault(),
                l.ProjectItemsConfigs
                .FirstOrDefault(p => input.Equals(p.solutionConfig) == true)
                .projectConfig
                    );

            Assert.Equal
            (
                new(p.GlobalProperties[PropertyNames.CONFIG], p.GlobalProperties[PropertyNames.PLATFORM]),
                input
            );
        }
コード例 #19
0
ファイル: PackagesConfigLocator.cs プロジェクト: 3F/MvsSln
 public static IEnumerable <string> FindConfigs(ISlnResult sln, SlnItems items)
 => FindAllConfigs(sln, items).Distinct();
コード例 #20
0
ファイル: PackagesConfigLocator.cs プロジェクト: 3F/MvsSln
 public static IEnumerable <PackagesConfig> FindAndLoadConfigs(ISlnResult sln, SlnItems items)
 => FindConfigs(sln, items)
 .Select(c => new PackagesConfig(c, PackagesConfigOptions.Load
                                 | PackagesConfigOptions.PathToStorage
                                 | PackagesConfigOptions.SilentLoading));