Exemple #1
0
        /// <summary>
        /// Project.json based project system.
        /// </summary>
        /// <param name="jsonConfig">Path to project.json.</param>
        /// <param name="msBuildProjectPath">Path to the msbuild project file.</param>
        public ProjectJsonBuildIntegratedNuGetProject(
            string jsonConfig,
            string msBuildProjectPath)
        {
            if (jsonConfig == null)
            {
                throw new ArgumentNullException(nameof(jsonConfig));
            }

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

            _jsonConfig = new FileInfo(jsonConfig);

            MSBuildProjectPath = msBuildProjectPath;

            _projectName = Path.GetFileNameWithoutExtension(msBuildProjectPath);

            if (string.IsNullOrEmpty(_projectName))
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.CurrentCulture, Strings.InvalidProjectName, MSBuildProjectPath));
            }

            JObject projectJson;
            IEnumerable <NuGetFramework> targetFrameworks = Enumerable.Empty <NuGetFramework>();

            try
            {
                projectJson      = GetJson();
                targetFrameworks = JsonConfigUtility.GetFrameworks(projectJson);
            }
            catch (InvalidOperationException)
            {
                // Ignore a bad project.json when constructing the project, and treat it as unsupported.
            }

            // Default to unsupported if anything unexpected is returned
            var targetFramework = NuGetFramework.UnsupportedFramework;

            // Having more than one framework is not supported, but we pick the first as fallback
            // We will eventually support more than one framework ala projectK.
            if (targetFrameworks.Count() == 1)
            {
                targetFramework = targetFrameworks.First();
            }

            InternalMetadata.Add(NuGetProjectMetadataKeys.TargetFramework, targetFramework);
            InternalMetadata.Add(NuGetProjectMetadataKeys.Name, _projectName);
            InternalMetadata.Add(NuGetProjectMetadataKeys.FullPath, msBuildProjectPath);

            var supported = new List <FrameworkName>
            {
                new FrameworkName(targetFramework.DotNetFrameworkName)
            };

            InternalMetadata.Add(NuGetProjectMetadataKeys.SupportedFrameworks, supported);
        }
        public void JsonConfigUtility_GetTargetFramework()
        {
            // Arrange
            var json = BasicConfig;

            // Act
            var frameworks = JsonConfigUtility.GetFrameworks(json);

            // Assert
            Assert.Equal("netcore50", frameworks.Single().GetShortFolderName());
        }
        private void UpdateFramework(JObject json)
        {
            var frameworks = JsonConfigUtility.GetFrameworks(json);

            if (InternalMetadata.TryGetValue(NuGetProjectMetadataKeys.TargetFramework, out object newTargetFramework))
            {
                if (IsUAPFramework(newTargetFramework as NuGetFramework) && frameworks.Count() == 1)
                {
                    // project.json can have only one target framework
                    JsonConfigUtility.ClearFrameworks(json);
                    JsonConfigUtility.AddFramework(json, newTargetFramework as NuGetFramework);
                }
            }
        }
        public void JsonConfigUtility_ClearFrameworks()
        {
            // Arrange
            var json = BasicConfig;

            var frameworks = JsonConfigUtility.GetFrameworks(json);

            Assert.Equal("netcore50", frameworks.Single().GetShortFolderName());

            // Act
            JsonConfigUtility.ClearFrameworks(json);
            frameworks = JsonConfigUtility.GetFrameworks(json);

            //Assert
            Assert.Equal(0, frameworks.Count());
        }
        public void JsonConfigUtility_AddFramework()
        {
            // Arrange
            var json = BasicConfig;

            var frameworks = JsonConfigUtility.GetFrameworks(json);

            Assert.Equal(1, frameworks.Count());

            // Act
            JsonConfigUtility.AddFramework(json, new NuGet.Frameworks.NuGetFramework("uap", new Version("10.0.0")));
            frameworks = JsonConfigUtility.GetFrameworks(json);

            //Assert
            Assert.Equal(2, frameworks.Count());
        }
Exemple #6
0
        private async Task UpdateFrameworkAsync(JObject json)
        {
            // Update the internal target framework with TPMinV from csproj
            await UpdateInternalTargetFrameworkAsync();

            if (TryGetInternalFramework(out object newTargetFrameworkObject))
            {
                var frameworks         = JsonConfigUtility.GetFrameworks(json);
                var newTargetFramework = newTargetFrameworkObject as NuGetFramework;
                if (IsUAPFramework(newTargetFramework) &&
                    frameworks.Count() == 1 &&
                    frameworks.Single() != newTargetFramework)
                {
                    // project.json can have only one target framework
                    JsonConfigUtility.ClearFrameworks(json);
                    JsonConfigUtility.AddFramework(json, newTargetFramework as NuGetFramework);
                }
            }
        }