void ReadProject(string frameworkMoniker = ".NETCoreApp,Version=v1.0")
        {
            var moniker = TargetFrameworkMoniker.Parse(frameworkMoniker);

            project.ReadProjectHeader(msbuildProject);
            project.ReadProject(msbuildProject, moniker);
        }
        public SystemPackageInfo GetPackageInfo()
        {
            SystemPackageInfo pi = new SystemPackageInfo();

            pi.Name    = name;
            pi.Version = version;

            if (fxVersion != null)
            {
                pi.TargetFramework = TargetFrameworkMoniker.Parse(fxVersion);
            }
            else if (clrVersion == ClrVersion.Net_1_1)
            {
                pi.TargetFramework = TargetFrameworkMoniker.NET_1_1;
            }
            else if (clrVersion == ClrVersion.Net_2_0)
            {
                pi.TargetFramework = TargetFrameworkMoniker.NET_2_0;
            }

            if (hasGacRoot)
            {
                pi.GacRoot = Addin.GetFilePath(".");
            }

            return(pi);
        }
        FakeDotNetProject CreateProjectWithTargetFramework(string targetFramework)
        {
            var project = new FakeDotNetProject();

            project.TargetFrameworkMoniker = TargetFrameworkMoniker.Parse(targetFramework);
            return(project);
        }
        [TestCase(".NETCoreApp", "2.1", new [] { "2.1.400" }, false, true)]                 // v2.1.400 will support .NET Core  2.1
        public void IsSupportedTargetFramework(
            string frameworkIdentifier,
            string frameworkVersion,
            string[] installedSdkVersions,
            bool msbuildSdksInstalled,             // True if Mono has the .NET Core sdks.
            bool expected)
        {
            string framework = $"{frameworkIdentifier},Version=v{frameworkVersion}";
            var    targetFrameworkMoniker = TargetFrameworkMoniker.Parse(framework);
            var    versions = installedSdkVersions.Select(version => DotNetCoreVersion.Parse(version))
                              .OrderByDescending(version => version)
                              .ToArray();

            bool actual = DotNetCoreSdk.IsSupported(targetFrameworkMoniker, versions, msbuildSdksInstalled);

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void CreatePackageSpec_NonDotNetCoreProjectWithOnePackageReference_TargetFrameworkTakenFromProjectNotTargetFrameworkProperty()
        {
            CreateProject("MyProject", @"d:\projects\MyProject\MyProject.csproj");
            project.TargetFrameworkMoniker = TargetFrameworkMoniker.Parse(".NETFramework,Version=v4.6.1");
            AddPackageReference("Newtonsoft.Json", "9.0.1");

            CreatePackageSpec();

            var targetFramework = spec.TargetFrameworks.Single();
            var dependency      = targetFramework.Dependencies.Single();

            Assert.AreEqual("MyProject", spec.Name);
            Assert.AreEqual(ProjectStyle.PackageReference, spec.RestoreMetadata.ProjectStyle);
            Assert.AreEqual("MyProject", spec.RestoreMetadata.ProjectName);
            Assert.AreEqual(".NETFramework,Version=v4.6.1", targetFramework.FrameworkName.ToString());
            Assert.AreEqual("net461", spec.RestoreMetadata.OriginalTargetFrameworks.Single());
            Assert.AreEqual("Newtonsoft.Json", dependency.Name);
            Assert.AreEqual(LibraryDependencyType.Default, dependency.Type);
            Assert.AreEqual(LibraryIncludeFlags.All, dependency.IncludeType);
            Assert.AreEqual(LibraryIncludeFlagUtils.DefaultSuppressParent, dependency.SuppressParent);
            Assert.AreEqual("[9.0.1, )", dependency.LibraryRange.VersionRange.ToString());
            Assert.AreEqual(LibraryDependencyTarget.Package, dependency.LibraryRange.TypeConstraint);
            Assert.AreEqual("Newtonsoft.Json", dependency.LibraryRange.Name);
        }
Exemple #6
0
 public TargetFrameworkMoniker GetTargetFrameworkMoniker()
 {
     return(TargetFrameworkMoniker.Parse(Include));
 }
        public virtual void Deserialize(object obj, ITypeSerializer handler, DataCollection data)
        {
            if (obj is ProjectFile)
            {
                ProjectFile pf = (ProjectFile)obj;

                //Map the old FileCopy action to the Content BuildAction with CopyToOutputDirectory set to "always"
                //BuildActionDataType handles mapping the BuildAction to "Content"
                DataValue value      = data ["buildaction"] as DataValue;
                bool      isFileCopy = value != null && value.Value == "FileCopy";

                DataValue resourceId = data.Extract("resource_id") as DataValue;

                handler.Deserialize(obj, data);
                if (isFileCopy)
                {
                    pf.CopyToOutputDirectory = FileCopyMode.Always;
                }

                if (resourceId != null)
                {
                    pf.ResourceId = resourceId.Value;
                }
            }
            else if (obj is SolutionEntityItem)
            {
                DataValue ac       = null;
                DataItem  confItem = data ["Configurations"] as DataItem;
                if (confItem != null)
                {
                    ac = (DataValue)confItem.ItemData.Extract("active");
                }

                DataItem items = data.Extract("Items") as DataItem;
                if (items != null)
                {
                    ReadItems(handler, (SolutionEntityItem)obj, items);
                }

                handler.Deserialize(obj, data);
                if (ac != null)
                {
                    SolutionEntityItem item = (SolutionEntityItem)obj;
                    item.DefaultConfigurationId = ac.Value;
                }
                DotNetProject np = obj as DotNetProject;
                if (np != null)
                {
                    // Import the framework version
                    TargetFrameworkMoniker fx = null;
                    DataValue vfx             = data["targetFramework"] as DataValue;
                    if (vfx != null)
                    {
                        fx = TargetFrameworkMoniker.Parse(vfx.Value);
                    }
                    else
                    {
                        vfx = data ["clr-version"] as DataValue;
                        if (vfx != null && vfx.Value == "Net_2_0")
                        {
                            fx = TargetFrameworkMoniker.NET_2_0;
                        }
                        else if (vfx != null && vfx.Value == "Net_1_1")
                        {
                            fx = TargetFrameworkMoniker.NET_1_1;
                        }
                    }
                    if (fx != null)
                    {
                        np.TargetFramework = Runtime.SystemAssemblyService.GetTargetFramework(fx);
                    }

                    // Get the compile target from one of the configurations
                    if (np.Configurations.Count > 0)
                    {
                        np.CompileTarget = (CompileTarget)Enum.Parse(typeof(CompileTarget), (string)np.Configurations [0].ExtendedProperties ["Build/target"]);
                    }
                }
            }
            else if (obj is ProjectReference)
            {
                ProjectReference pref  = (ProjectReference)obj;
                DataValue        refto = data.Extract("refto") as DataValue;
                handler.Deserialize(obj, data);
                if (refto != null)
                {
                    pref.Reference = refto.Value;
                    if (pref.ReferenceType == ReferenceType.Assembly)
                    {
                        string basePath = Path.GetDirectoryName(handler.SerializationContext.BaseFile);
                        pref.Reference = FileService.RelativeToAbsolutePath(basePath, pref.Reference);
                    }
                }
            }
            else
            {
                handler.Deserialize(obj, data);
            }
        }
Exemple #8
0
        public async Task NetStandardLibrary_NewtonsoftJsonNuGetPackageReference()
        {
            FilePath projectFileName = Util.GetSampleProject("DotNetCoreDependenciesFolder", "NetStandardJsonNet.csproj");

            Restore(projectFileName);
            project = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projectFileName);
            await CreateDependenciesNode();

            var sdkNode = GetSdkFolderChildDependencies().Single();

            Assert.AreEqual("NETStandard.Library", sdkNode.Name);
            Assert.AreEqual("NETStandard.Library", sdkNode.GetLabel());
            Assert.IsTrue(sdkNode.IsReadOnly);
            Assert.IsFalse(sdkNode.CanBeRemoved);
            Assert.IsTrue(sdkNode.IsTopLevel);

            var childNodes          = sdkNode.GetDependencyNodes().ToList();
            var systemThreadingNode = childNodes.FirstOrDefault(node => node.Name == "System.Threading");

            Assert.IsFalse(systemThreadingNode.CanBeRemoved);
            Assert.IsFalse(systemThreadingNode.IsTopLevel);

            var defaultNode = sdkFolderNode.GetDefaultNodes().Single();

            Assert.AreEqual("NETStandard.Library", defaultNode.Name);
            Assert.AreEqual("NETStandard.Library", defaultNode.GetLabel());

            var newtonsoftNode = GetNuGetFolderChildDependencies().Single();

            Assert.AreEqual("Newtonsoft.Json", newtonsoftNode.Name);
            Assert.AreEqual("Newtonsoft.Json", newtonsoftNode.GetLabel());
            Assert.AreEqual("(10.0.3)", newtonsoftNode.GetSecondaryLabel());
            Assert.IsTrue(newtonsoftNode.CanBeRemoved);
            Assert.IsFalse(newtonsoftNode.IsReadOnly);
            Assert.IsTrue(newtonsoftNode.IsTopLevel);
            Assert.IsTrue(newtonsoftNode.IsReleaseVersion());
            Assert.IsTrue(newtonsoftNode.HasDependencies());

            childNodes = newtonsoftNode.GetDependencyNodes().ToList();
            var microsoftCSharpNode = childNodes.FirstOrDefault(node => node.Name == "Microsoft.CSharp");

            Assert.IsFalse(microsoftCSharpNode.CanBeRemoved);
            Assert.IsFalse(microsoftCSharpNode.IsTopLevel);

            var packageReferenceNode = nugetFolderNode.GetProjectPackageReferencesAsDependencyNodes().Single();

            Assert.AreEqual("Newtonsoft.Json", packageReferenceNode.Name);
            Assert.AreEqual("Newtonsoft.Json", packageReferenceNode.GetLabel());
            Assert.AreEqual("(10.0.3)", packageReferenceNode.GetSecondaryLabel());
            Assert.IsTrue(packageReferenceNode.CanBeRemoved);
            Assert.IsFalse(packageReferenceNode.IsReadOnly);
            Assert.IsTrue(packageReferenceNode.IsTopLevel);
            Assert.IsTrue(packageReferenceNode.IsReleaseVersion());
            Assert.IsFalse(packageReferenceNode.HasDependencies());

            // Check default sdk if project converted from .NET Standard to .NET Core 1.1.
            var moniker = TargetFrameworkMoniker.Parse(".NETCoreApp,Version=v1.1");

            project.TargetFramework = Runtime.SystemAssemblyService.GetTargetFramework(moniker);

            defaultNode = sdkFolderNode.GetDefaultNodes().Single();
            Assert.AreEqual("Microsoft.NETCore.App", defaultNode.Name);
            Assert.AreEqual("Microsoft.NETCore.App", defaultNode.GetLabel());
        }