コード例 #1
0
        /// <summary>
        /// Check if solution is open. If not, throw terminating error
        /// </summary>
        protected void CheckSolutionState()
        {
            if (!VsSolutionManager.IsSolutionOpen)
            {
                ErrorHandler.ThrowSolutionNotOpenTerminatingError();
            }

            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                if (!(await VsSolutionManager.IsSolutionAvailableAsync()))
                {
                    ErrorHandler.HandleException(
                        new InvalidOperationException(VisualStudio.Strings.SolutionIsNotSaved),
                        terminating: true,
                        errorId: NuGetErrorId.UnsavedSolution,
                        category: ErrorCategory.InvalidOperation);
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Get the default NuGet Project
        /// </summary>
        /// <param name="projectName"></param>
        protected async Task GetNuGetProjectAsync(string projectName = null)
        {
            if (string.IsNullOrEmpty(projectName))
            {
                Project = await VsSolutionManager.GetDefaultNuGetProjectAsync();

                if ((await VsSolutionManager.IsSolutionAvailableAsync()) &&
                    Project == null)
                {
                    ErrorHandler.WriteProjectNotFoundError("Default", terminating: true);
                }
            }
            else
            {
                Project = await VsSolutionManager.GetNuGetProjectAsync(projectName);

                if ((await VsSolutionManager.IsSolutionAvailableAsync()) &&
                    Project == null)
                {
                    ErrorHandler.WriteProjectNotFoundError(projectName, terminating: true);
                }
            }
        }