public IEnumerable<SourceRepository> GetRepositories (ProjectTemplatePackageReference packageReference)
		{
			if (packageReference.Directory.IsNotNull) {
				yield return CreateRepository (packageReference.Directory);
				yield break;
			}

			foreach (SourceRepository sourceRepository in GetProjectTemplateRepositories ()) {
				if (!packageReference.IsLocalPackage || sourceRepository.PackageSource.IsLocal) {
					yield return sourceRepository;
				}
			}

			if (!packageReference.IsLocalPackage) {
				yield return nugetSourceRepository;
			}
		}
예제 #2
0
        public static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory)
        {
            ProjectDescriptor projectDescriptor = new ProjectDescriptor();

            projectDescriptor.name            = xmlElement.GetAttribute("name");
            projectDescriptor.directory       = xmlElement.GetAttribute("directory");
            projectDescriptor.createCondition = xmlElement.GetAttribute("if");

            projectDescriptor.type = xmlElement.GetAttribute("type");

            if (xmlElement ["Files"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        projectDescriptor.files.Add(
                            FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory));
                    }
                }
            }

            if (xmlElement ["Resources"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory);
                        if (fileTemplate is SingleFileDescriptionTemplate)
                        {
                            projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate);
                        }
                        else
                        {
                            MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files"));
                        }
                    }
                }
            }

            if (xmlElement ["References"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes)
                {
                    projectDescriptor.references.Add(new ProjectReferenceDescription((XmlElement)xmlNode));
                }
            }

            projectDescriptor.projectOptions = xmlElement ["Options"];
            if (projectDescriptor.projectOptions == null)
            {
                projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options");
            }

            if (xmlElement ["Packages"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Packages"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var packageReference = ProjectTemplatePackageReference.Create((XmlElement)xmlNode, baseDirectory);
                        projectDescriptor.packageReferences.Add(packageReference);
                    }
                }
            }

            return(projectDescriptor);
        }
		SemanticVersion GetPackageVersion (ProjectTemplatePackageReference packageReference)
		{
			if (!string.IsNullOrEmpty (packageReference.Version)) {
				return new SemanticVersion (packageReference.Version);
			}
			return null;
		}
		/// <summary>
		/// If the package is a local package then we prevent NuGet from using online package sources
		/// defined in the NuGet.Config file by using the returning the primaryRepositories. 
		/// Returning null allows all enabled package sources to be used when resolving dependencies.
		/// </summary>
		static IEnumerable<SourceRepository> GetSecondaryRepositories (
			IEnumerable<SourceRepository> primaryRepositories, ProjectTemplatePackageReference packageReference)
		{
			if (packageReference.IsLocalPackage || packageReference.Directory.IsNotNull) {
				return primaryRepositories;
			}
			return null;
		}
		InstallNuGetPackageAction CreateInstallNuGetPackageAction (
			DotNetProject dotNetProject,
			ProjectTemplateSourceRepositoryProvider repositoryProvider,
			ProjectTemplatePackageReference packageReference)
		{
			var primaryRepositories = repositoryProvider.GetRepositories (packageReference).ToList ();
			var secondaryRepositories = GetSecondaryRepositories (primaryRepositories, packageReference);

			return new InstallNuGetPackageAction (
				primaryRepositories,
				secondaryRepositories,
				PackageManagementServices.Workspace.GetSolutionManager (dotNetProject.ParentSolution),
				new DotNetProjectProxy (dotNetProject),
				new NuGetProjectContext ());
		}
예제 #6
0
        public static ProjectDescriptor CreateProjectDescriptor(XmlElement xmlElement, FilePath baseDirectory)
        {
            ProjectDescriptor projectDescriptor = new ProjectDescriptor();

            projectDescriptor.name      = xmlElement.GetAttribute("name");
            projectDescriptor.directory = xmlElement.GetAttribute("directory");

            projectDescriptor.type = xmlElement.GetAttribute("type");
            if (String.IsNullOrEmpty(projectDescriptor.type))
            {
                projectDescriptor.type = "DotNet";
            }

            if (xmlElement ["Files"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Files"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        projectDescriptor.files.Add(
                            FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory));
                    }
                }
            }

            if (xmlElement ["Resources"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Resources"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var fileTemplate = FileDescriptionTemplate.CreateTemplate((XmlElement)xmlNode, baseDirectory);
                        if (fileTemplate is SingleFileDescriptionTemplate)
                        {
                            projectDescriptor.resources.Add((SingleFileDescriptionTemplate)fileTemplate);
                        }
                        else
                        {
                            MessageService.ShowError(GettextCatalog.GetString("Only single-file templates allowed to generate resource files"));
                        }
                    }
                }
            }

            if (xmlElement ["References"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["References"].ChildNodes)
                {
                    XmlElement       elem             = (XmlElement)xmlNode;
                    var              refType          = elem.GetAttribute("type");
                    ProjectReference projectReference = new ProjectReference((ReferenceType)Enum.Parse(typeof(ReferenceType), refType), elem.GetAttribute("refto"));
                    string           specificVersion  = elem.GetAttribute("SpecificVersion");
                    if (!string.IsNullOrEmpty(specificVersion))
                    {
                        projectReference.SpecificVersion = bool.Parse(specificVersion);
                    }
                    string localCopy = elem.GetAttribute("LocalCopy");
                    if (!string.IsNullOrEmpty(localCopy) && projectReference.CanSetLocalCopy)
                    {
                        projectReference.LocalCopy = bool.Parse(localCopy);
                    }
                    projectDescriptor.references.Add(projectReference);
                }
            }

            projectDescriptor.projectOptions = xmlElement ["Options"];
            if (projectDescriptor.projectOptions == null)
            {
                projectDescriptor.projectOptions = xmlElement.OwnerDocument.CreateElement("Options");
            }

            if (xmlElement ["Packages"] != null)
            {
                foreach (XmlNode xmlNode in xmlElement["Packages"].ChildNodes)
                {
                    if (xmlNode is XmlElement)
                    {
                        var packageReference = ProjectTemplatePackageReference.Create((XmlElement)xmlNode);
                        projectDescriptor.packageReferences.Add(packageReference);
                    }
                }
            }

            return(projectDescriptor);
        }