Example #1
0
        public void ToProjectRestoreInfo_SetsProjectReferences()
        {
            var update = IProjectSubscriptionUpdateFactory.FromJson(ProjectWithItems);

            var result = RestoreBuilder.ToProjectRestoreInfo(update.CurrentState);

            Assert.Equal(1, result.TargetFrameworks.Count);

            var references = result.TargetFrameworks.Item(0).ProjectReferences;

            Assert.Equal(3, references.Count);

            Assert.Equal("..\\Project\\Project1.csproj", references.Item("..\\Project\\Project1.csproj").Name);
            Assert.Equal("ProjectFileFullPath", references.Item("..\\Project\\Project1.csproj").Properties.Item("ProjectFileFullPath").Name);
            Assert.Equal("C:\\Solution\\Project\\Project1.csproj", references.Item("..\\Project\\Project1.csproj").Properties.Item("ProjectFileFullPath").Value);

            Assert.Equal("..\\Project\\Project2.csproj", references.Item("..\\Project\\Project2.csproj").Name);
            Assert.Equal("ProjectFileFullPath", references.Item("..\\Project\\Project2.csproj").Properties.Item("ProjectFileFullPath").Name);
            Assert.Equal("C:\\Solution\\Project\\Project2.csproj", references.Item("..\\Project\\Project2.csproj").Properties.Item("ProjectFileFullPath").Value);

            Assert.Equal("..\\Project\\Project3.csproj", references.Item("..\\Project\\Project3.csproj").Name);
            Assert.Equal("ProjectFileFullPath", references.Item("..\\Project\\Project3.csproj").Properties.Item("ProjectFileFullPath").Name);
            Assert.Equal("C:\\Solution\\Project\\Project3.csproj", references.Item("..\\Project\\Project3.csproj").Properties.Item("ProjectFileFullPath").Value);
            Assert.Equal("Property", references.Item("..\\Project\\Project3.csproj").Properties.Item("Property").Name);
            Assert.Equal("Value", references.Item("..\\Project\\Project3.csproj").Properties.Item("Property").Value);
        }
Example #2
0
        public void ToProjectRestoreInfo_SetsCoreProperties()
        {
            var update = IProjectSubscriptionUpdateFactory.FromJson(ProjectWithEmptyItems);

            var result = RestoreBuilder.ToProjectRestoreInfo(update.CurrentState);

            Assert.Equal("C:\\Project\\obj", result.BaseIntermediatePath);
            Assert.Equal("net45", result.OriginalTargetFrameworks);
            Assert.Equal(1, result.TargetFrameworks.Count);
            Assert.Equal(".NETFramework, Version=v4.5", result.TargetFrameworks.Item(0).TargetFrameworkMoniker);
        }
Example #3
0
        public void ToProjectRestoreInfo_WhenNoItems_ReturnsEmptyItemCollections()
        {
            var update = IProjectSubscriptionUpdateFactory.FromJson(ProjectWithEmptyItems);

            var result = RestoreBuilder.ToProjectRestoreInfo(update.CurrentState);

            Assert.Empty(result.ToolReferences);
            Assert.Equal(1, result.TargetFrameworks.Count);

            var targetFramework = result.TargetFrameworks.Item(0);

            Assert.Empty(targetFramework.PackageReferences);
            Assert.Empty(targetFramework.ProjectReferences);
        }
Example #4
0
        public void ToProjectRestoreInfo_SetsToolReferences()
        {
            var update = IProjectSubscriptionUpdateFactory.FromJson(ProjectWithItems);

            var result     = RestoreBuilder.ToProjectRestoreInfo(update.CurrentState);
            var references = result.ToolReferences;

            Assert.Equal(3, references.Count);

            Assert.Equal("ToolReference1", references.Item("ToolReference1").Name);
            Assert.Equal("Version", references.Item("ToolReference1").Properties.Item("Version").Name);
            Assert.Equal("1.0.0.0", references.Item("ToolReference1").Properties.Item("Version").Value);

            Assert.Equal("ToolReference2", references.Item("ToolReference2").Name);
            Assert.Equal("Version", references.Item("ToolReference2").Properties.Item("Version").Name);
            Assert.Equal("2.0.0.0", references.Item("ToolReference2").Properties.Item("Version").Value);

            Assert.Equal("ToolReference3", references.Item("ToolReference3").Name);
            Assert.Equal("Name", references.Item("ToolReference3").Properties.Item("Name").Name);
            Assert.Equal("Value", references.Item("ToolReference3").Properties.Item("Name").Value);
        }
Example #5
0
        public void ToProjectRestoreInfo_SetsTargetFrameworkPropertiesToAllProperties()
        {
            var update = IProjectSubscriptionUpdateFactory.FromJson(ProjectWithEmptyItems);

            var result = RestoreBuilder.ToProjectRestoreInfo(update.CurrentState);

            Assert.Equal(1, result.TargetFrameworks.Count);

            var properties = result.TargetFrameworks.Item(0).Properties;

            Assert.Equal("MSBuildProjectExtensionsPath", properties.Item("MSBuildProjectExtensionsPath").Name);
            Assert.Equal("C:\\Project\\obj", properties.Item("MSBuildProjectExtensionsPath").Value);

            Assert.Equal("TargetFrameworks", properties.Item("TargetFrameworks").Name);
            Assert.Equal("net45", properties.Item("TargetFrameworks").Value);

            Assert.Equal("TargetFrameworkMoniker", properties.Item("TargetFrameworkMoniker").Name);
            Assert.Equal(".NETFramework, Version=v4.5", properties.Item("TargetFrameworkMoniker").Value);

            Assert.Equal("Property", properties.Item("Property").Name);
            Assert.Equal("Value", properties.Item("Property").Value);
        }
Example #6
0
        internal static IVsProjectRestoreInfo Build(IEnumerable <IProjectVersionedValue <IProjectSubscriptionUpdate> > updates)
        {
            Requires.NotNull(updates, nameof(updates));

            // if none of the underlying subscriptions have any changes
            if (!updates.Any(u => u.Value.ProjectChanges.Any(c => c.Value.Difference.AnyChanges)))
            {
                return(null);
            }

            string msbuildProjectExtensionsPath = null;
            string originalTargetFrameworks     = null;
            var    targetFrameworks             = ImmutableDictionary.Create <string, IVsTargetFrameworkInfo>(StringComparers.ItemNames);
            var    toolReferences = ImmutableDictionary.Create <string, IVsReferenceItem>(StringComparers.ItemNames);

            foreach (IProjectVersionedValue <IProjectSubscriptionUpdate> update in updates)
            {
                IProjectChangeDescription nugetRestoreChanges = update.Value.ProjectChanges[NuGetRestore.SchemaName];
                msbuildProjectExtensionsPath = msbuildProjectExtensionsPath ??
                                               nugetRestoreChanges.After.Properties[NuGetRestore.MSBuildProjectExtensionsPathProperty];
                originalTargetFrameworks = originalTargetFrameworks ??
                                           nugetRestoreChanges.After.Properties[NuGetRestore.TargetFrameworksProperty];
                bool noTargetFramework =
                    !update.Value.ProjectConfiguration.Dimensions.TryGetValue(NuGetRestore.TargetFrameworkProperty, out string targetFramework) &&
                    !nugetRestoreChanges.After.Properties.TryGetValue(NuGetRestore.TargetFrameworkProperty, out targetFramework);

                if (noTargetFramework || string.IsNullOrEmpty(targetFramework))
                {
                    TraceUtilities.TraceWarning("Unable to find TargetFramework Property");
                    continue;
                }

                if (!targetFrameworks.ContainsKey(targetFramework))
                {
                    IProjectChangeDescription projectReferencesChanges = update.Value.ProjectChanges[ProjectReference.SchemaName];
                    IProjectChangeDescription packageReferencesChanges = update.Value.ProjectChanges[PackageReference.SchemaName];

                    targetFrameworks = targetFrameworks.Add(targetFramework, new TargetFrameworkInfo(
                                                                targetFramework,
                                                                RestoreBuilder.ToReferenceItems(projectReferencesChanges.After.Items),
                                                                RestoreBuilder.ToReferenceItems(packageReferencesChanges.After.Items),
                                                                RestoreBuilder.ToProjectProperties(nugetRestoreChanges.After.Properties)
                                                                ));
                }

                IProjectChangeDescription toolReferencesChanges = update.Value.ProjectChanges[DotNetCliToolReference.SchemaName];
                foreach (KeyValuePair <string, IImmutableDictionary <string, string> > item in toolReferencesChanges.After.Items)
                {
                    if (!toolReferences.ContainsKey(item.Key))
                    {
                        toolReferences = toolReferences.Add(item.Key, RestoreBuilder.ToReferenceItem(item.Key, item.Value));
                    }
                }
            }

            // return nominate restore information if any target framework entries are found
            return(targetFrameworks.Count > 0
                ? new ProjectRestoreInfo(
                       // NOTE: We pass MSBuildProjectExtensionsPath as BaseIntermediatePath instead of using
                       // BaseIntermediateOutputPath. This is because NuGet switched from using BaseIntermediateOutputPath
                       // to MSBuildProjectExtensionsPath, since the value of BaseIntermediateOutputPath is often set too
                       // late (after *.g.props files would need to have been imported from it). Instead of modifying the
                       // IVsProjectRestoreInfo interface or introducing something like IVsProjectRestoreInfo with an
                       // MSBuildProjectExtensionsPath property, we opted to leave the interface the same but change the
                       // meaning of its BaseIntermediatePath property. See
                       // https://github.com/dotnet/project-system/issues/3466for for details.
                       msbuildProjectExtensionsPath,
                       originalTargetFrameworks,
                       new TargetFrameworks(targetFrameworks.Values),
                       new ReferenceItems(toolReferences.Values)
                       )
                : null);
        }
        private ProjectRestoreUpdate CreateRestoreUpdate(ProjectConfiguration projectConfiguration, IImmutableDictionary <string, IProjectRuleSnapshot> update)
        {
            IVsProjectRestoreInfo restoreInfo = RestoreBuilder.ToProjectRestoreInfo(update);

            return(new ProjectRestoreUpdate(projectConfiguration, restoreInfo));
        }