Exemple #1
0
        /// <summary>
        /// Finds the NuGetProject from a DTE project
        /// </summary>
        public static async Task <NuGetProject> GetProjectAsync(ISolutionManager solutionManager, Project project, VSAPIProjectContext projectContext = null)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (solutionManager == null)
            {
                throw new ArgumentNullException("solution");
            }

            var projectSafeName = await EnvDTEProjectUtility.GetCustomUniqueNameAsync(project);

            NuGetProject nuGetProject = solutionManager.GetNuGetProject(projectSafeName);

            var settings = ServiceLocator.GetInstance <Configuration.ISettings>();

            // if the project does not exist in the solution (this is true for new templates) create it manually
            if (nuGetProject == null)
            {
                VSNuGetProjectFactory factory =
                    new VSNuGetProjectFactory(() => PackagesFolderPathUtility.GetPackagesFolderPath(solutionManager, settings));
                nuGetProject = factory.CreateNuGetProject(project, projectContext);
            }

            return(nuGetProject);
        }
        /// <summary>
        /// Finds the NuGetProject from a DTE project
        /// </summary>
        public static NuGetProject GetProject(ISolutionManager solutionManager, Project project, VSAPIProjectContext projectContext=null)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solution");
            }

            var projectSafeName = EnvDTEProjectUtility.GetCustomUniqueName(project);
            NuGetProject nuGetProject = solutionManager.GetNuGetProject(projectSafeName);

            var settings = ServiceLocator.GetInstance<ISettings>();

            // if the project does not exist in the solution (this is true for new templates) create it manually
            if (nuGetProject == null)
            {
                VSNuGetProjectFactory factory = new VSNuGetProjectFactory(() => PackagesFolderPathUtility.GetPackagesFolderPath(solutionManager, settings));
                nuGetProject = factory.CreateNuGetProject(project, projectContext);
            }

            return nuGetProject;
        }
Exemple #3
0
        /// <summary>
        /// Finds the NuGetProject from a DTE project
        /// </summary>
        public static NuGetProject GetProject(ISolutionManager solutionManager, Project project, VSAPIProjectContext projectContext = null)
        {
            if (solutionManager == null)
            {
                throw new ArgumentNullException("solution");
            }

            var          projectSafeName = EnvDTEProjectUtility.GetCustomUniqueName(project);
            NuGetProject nuGetProject    = solutionManager.GetNuGetProject(projectSafeName);

            var settings = ServiceLocator.GetInstance <ISettings>();

            // if the project does not exist in the solution (this is true for new templates) create it manually
            if (nuGetProject == null)
            {
                VSNuGetProjectFactory factory = new VSNuGetProjectFactory(() => PackagesFolderPathUtility.GetPackagesFolderPath(solutionManager, settings));
                nuGetProject = factory.CreateNuGetProject(project, projectContext);
            }

            return(nuGetProject);
        }
        public void Initialize(IEnumerable<Project> projects, VSNuGetProjectFactory factory)
        {
            foreach (EnvDTEProject project in projects)
            {
                AddProject(project, factory);
            }

            IsInitialized = true;
        }
        /// <summary>
        /// Add a project to the cache.
        /// </summary>
        /// <param name="project">project to add to the cache.</param>
        /// <returns>The project name of the added project.</returns>
        public EnvDTEProjectName AddProject(EnvDTEProject project, VSNuGetProjectFactory factory)
        {
            // First create a project name from the project
            var EnvDTEProjectName = new EnvDTEProjectName(project);

            // Do nothing if we already have an entry
            if (_envDTEProjectCache.ContainsKey(EnvDTEProjectName))
            {
                return EnvDTEProjectName;
            }

            AddShortName(EnvDTEProjectName);

            _projectNamesCache[EnvDTEProjectName.CustomUniqueName] = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.UniqueName] = EnvDTEProjectName;
            _projectNamesCache[EnvDTEProjectName.FullName] = EnvDTEProjectName;

            // Add the entry mapping project name to the actual project
            _envDTEProjectCache[EnvDTEProjectName] = project;
            _nuGetProjectCache[EnvDTEProjectName] = factory.CreateNuGetProject(project);

            return EnvDTEProjectName;
        }