public VsTargetFrameworkInfo(
            string targetFrameworkMoniker,
            IEnumerable <IVsReferenceItem> packageReferences,
            IEnumerable <IVsReferenceItem> projectReferences,
            IEnumerable <IVsProjectProperty> projectProperties,
            bool addTargetFrameworkProperties = true)
        {
            if (string.IsNullOrEmpty(targetFrameworkMoniker))
            {
                throw new ArgumentException("Argument cannot be null or empty", nameof(targetFrameworkMoniker));
            }

            if (packageReferences == null)
            {
                throw new ArgumentNullException(nameof(packageReferences));
            }

            if (projectReferences == null)
            {
                throw new ArgumentNullException(nameof(projectReferences));
            }

            if (projectProperties == null)
            {
                throw new ArgumentNullException(nameof(projectProperties));
            }

            TargetFrameworkMoniker = targetFrameworkMoniker;
            PackageReferences      = new VsReferenceItems(packageReferences);
            ProjectReferences      = new VsReferenceItems(projectReferences);
            Properties             =
                addTargetFrameworkProperties
                ? new VsProjectProperties(ProjectRestoreInfoBuilder.GetTargetFrameworkProperties(targetFrameworkMoniker).Concat(projectProperties))
                : new VsProjectProperties(projectProperties);
        }
Esempio n. 2
0
        private TestContext NewCpsProject(
            string projectJson  = null,
            string projectName  = null,
            bool crossTargeting = false)
        {
            const string DefaultProjectJson = @"{
    ""frameworks"": {
        ""netcoreapp1.0"": {
            ""dependencies"": { }
        }
    }
}";

            if (projectName == null)
            {
                projectName = $"{Guid.NewGuid()}";
            }

            var projectLocation      = _testDirectory.Path;
            var projectFullPath      = Path.Combine(projectLocation, $"{projectName}.csproj");
            var baseIntermediatePath = Path.Combine(projectLocation, "obj");

            Directory.CreateDirectory(baseIntermediatePath);

            var spec    = JsonPackageSpecReader.GetPackageSpec(projectJson ?? DefaultProjectJson, projectName, projectFullPath);
            var builder = ProjectRestoreInfoBuilder.FromPackageSpec(
                spec,
                baseIntermediatePath,
                crossTargeting);

            return(new TestContext
            {
                ProjectFullPath = projectFullPath,
                Builder = builder
            });
        }