public ProjectInfo Create(string path, ProjectCollection projectCollection)
        {
            var project  = GetProject(path, projectCollection);
            var instance = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup);

            var targetFrameworks = instance.GetPropertyValue("TargetFrameworks");
            var targetFramework  = instance.GetPropertyValue("TargetFramework");

            var frameworks = new List <ProjectFrameworkInfo>();

            if (!string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(targetFramework))
            {
                // multi targeting
                foreach (var tfm in targetFrameworks.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    project.SetGlobalProperty("TargetFramework", tfm);
                    var innerBuild = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup);

                    var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(tfm), GetDependencies(innerBuild));

                    frameworks.Add(tfmInfo);
                }

                project.RemoveGlobalProperty("TargetFramework");
            }
            else if (!string.IsNullOrEmpty(targetFramework))
            {
                var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(targetFramework), GetDependencies(instance));

                frameworks.Add(tfmInfo);
            }

            var projectDir = Path.GetDirectoryName(path);

            var tools = GetTools(instance).ToArray();

            bool.TryParse(instance.GetPropertyValue("IsPackable"), out var isPackable);

            if (isPackable)
            {
                // the default packable setting is disabled for projects referencing this package.
                isPackable = !frameworks.SelectMany(f => f.Dependencies.Keys).Any(d => d.Equals("Microsoft.NET.Test.Sdk", StringComparison.OrdinalIgnoreCase));
            }

            var packageId      = instance.GetPropertyValue("PackageId");
            var packageVersion = instance.GetPropertyValue("PackageVersion");

            return(new ProjectInfo(path,
                                   frameworks,
                                   tools,
                                   isPackable,
                                   packageId,
                                   packageVersion));
        }
Exemple #2
0
        public ProjectInfo Create(string path, ProjectCollection projectCollection)
        {
            var project     = GetProject(path, projectCollection);
            var instance    = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup);
            var projExtPath = instance.GetPropertyValue("MSBuildProjectExtensionsPath");

            var targetFrameworks = instance.GetPropertyValue("TargetFrameworks");
            var targetFramework  = instance.GetPropertyValue("TargetFramework");

            var frameworks = new List <ProjectFrameworkInfo>();

            if (!string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(targetFramework))
            {
                // multi targeting
                foreach (var tfm in targetFrameworks.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    project.SetGlobalProperty("TargetFramework", tfm);
                    var innerBuild = project.CreateProjectInstance(ProjectInstanceSettings.ImmutableWithFastItemLookup);

                    var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(tfm), GetDependencies(innerBuild));

                    frameworks.Add(tfmInfo);
                }

                project.RemoveGlobalProperty("TargetFramework");
            }
            else if (!string.IsNullOrEmpty(targetFramework))
            {
                var tfmInfo = new ProjectFrameworkInfo(NuGetFramework.Parse(targetFramework), GetDependencies(instance));

                frameworks.Add(tfmInfo);
            }

            var projectDir = Path.GetDirectoryName(path);

            var tools = GetTools(instance).ToArray();

            bool.TryParse(instance.GetPropertyValue("IsPackable"), out var isPackable);
            var packageId      = instance.GetPropertyValue("PackageId");
            var packageVersion = instance.GetPropertyValue("PackageVersion");

            return(new ProjectInfo(path,
                                   projExtPath,
                                   frameworks,
                                   tools,
                                   isPackable,
                                   packageId,
                                   packageVersion));
        }