示例#1
0
        private void SetSolutionFilter(VsSolution solution)
        {
            ClearFilter();

            Filter.SolutionFilter          = solution;
            Filter.IsSolutionFilterEnabled = true;
        }
示例#2
0
        public void VsSolutionParserReadsProjectDetails()
        {
            // Arrange
            var solutionFileContent =
@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""SomeProject"", ""Test\Test.csproj"", ""{80E5FD2A-A29A-47C7-8DE9-853D14295BAC}""
EndProject";

            var projectContent =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
    <PropertyGroup>
        <ProjectGuid>{975304D3-BFFA-45B4-BBC9-9A27323A670C}</ProjectGuid>
        <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    </PropertyGroup>
</Project>";
            var solutionFile = CreateSolutionFile(solutionFileContent);
            var projectFile = CreateProjectFile(solutionFile, @"Test\Test.csproj", projectContent);

            // Act
            var solution = new VsSolution(solutionFile);
            var project = solution.Projects.First();

            // Assert
            Assert.Equal("SomeProject", project.ProjectName);
            Assert.Contains(new Guid("fae04ec0-301f-11d3-bf4b-00c04f79efbc"), project.ProjectTypeGuids);
            Assert.Equal(projectFile, project.AbsolutePath);
            Assert.True(project.IsWap);
            Assert.False(project.IsWebSite);
        }
        public void VsSolutionParserReadsProjectDetails()
        {
            // Arrange
            var solutionFileContent =
                @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""SomeProject"", ""Test\Test.csproj"", ""{80E5FD2A-A29A-47C7-8DE9-853D14295BAC}""
EndProject";

            var projectContent =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""4.0"" DefaultTargets=""Build"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
    <PropertyGroup>
        <ProjectGuid>{975304D3-BFFA-45B4-BBC9-9A27323A670C}</ProjectGuid>
        <ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    </PropertyGroup>
</Project>";
            var solutionFile = CreateSolutionFile(solutionFileContent);
            var projectFile  = CreateProjectFile(solutionFile, @"Test\Test.csproj", projectContent);

            // Act
            var solution = new VsSolution(solutionFile);
            var project  = solution.Projects.First();

            // Assert
            Assert.Equal("SomeProject", project.ProjectName);
            Assert.Contains(new Guid("fae04ec0-301f-11d3-bf4b-00c04f79efbc"), project.ProjectTypeGuids);
            Assert.Equal(projectFile, project.AbsolutePath);
            Assert.True(project.IsWap);
            Assert.False(project.IsWebSite);
        }
        void CreateVsSolution(string solutionFileName = @"d:\projects\test\Test.sln")
        {
            var helper = new SolutionHelper(solutionFileName);

            fakeProjectService = new FakePackageManagementProjectService();
            fakeProjectService.OpenSolution = helper.MSBuildSolution;
            solution = new VsSolution(fakeProjectService);
        }
示例#5
0
        public void MakeRelativePath_ParentPath()
        {
            String slnPath  = @"C:\users\myuser\documents\Visual Studio 10.0\Project\MySolution\";
            String filePath = Path.Combine(slnPath, @"..\..\MyProject\Files\File1.txt");
            String relative = VsSolution.MakeRelativePath(slnPath, Path.GetFullPath(filePath));

            Assert.Equal(@"..\..\MyProject\Files\File1.txt", relative);
        }
        void CreateVsSolution(string solutionFileName = @"d:\projects\test\Test.sln")
        {
            var msbuildSolution = new Solution(new MockProjectChangeWatcher());

            msbuildSolution.FileName        = solutionFileName;
            fakeProjectService              = new FakePackageManagementProjectService();
            fakeProjectService.OpenSolution = msbuildSolution;
            solution = new VsSolution(fakeProjectService);
        }
 protected override void Dispose(bool disposing)
 {
     if (_solutionEventsCookie != 0)
     {
         VsSolution.UnadviseSolutionEvents(_solutionEventsCookie);
         _solutionEventsCookie = 0;
     }
     _solutionEventsHandler = null;
     base.Dispose(disposing);
 }
        public void When_loading_solution_then_correct_projects_must_be_loaded()
        {
            //// Arrange
            var path = "../../../MyToolkit.sln";

            //// Act
            var solution = VsSolution.Load(path);

            //// Assert
            Assert.IsTrue(solution.Projects.Any(p => p.Path.EndsWith("\\MyToolkit.csproj")));
        }
        protected override void ReloadProject()
        {
            IVsSolution4 solution4 = VsSolution as IVsSolution4;

            VsSolution.GetProjectOfUniqueName(DteProject.UniqueName, out IVsHierarchy hierarchy);
            int hr = 0;

            hierarchy.GetGuidProperty(Constants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ProjectIDGuid, out Guid guid);
            ErrorHandler.ThrowOnFailure(hr);
            solution4.UnloadProject(guid, (uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser);
            solution4.ReloadProject(guid);
        }
        /// <summary>
        /// Returns the project in the solution,
        /// given a unique name.
        /// </summary>
        ///
        /// <param name="project">
        /// Full path to the solution project.
        /// </param>
        ///
        /// <returns>
        /// Pointer to the IVsHierarchy interface
        /// of the project referred to by project.
        /// </returns>
        ///
        /// <remarks>
        /// https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivshierarchy.
        /// </remarks>
        protected virtual IVsHierarchy GetProjectHierarchyItem(string project)
        {
            const int S_OK = 0;

            int exitCode = VsSolution.GetProjectOfUniqueName(project, out IVsHierarchy hierarchyItem);

            if (exitCode != S_OK)
            {
                AddMessage($"Exit code: { exitCode }", MessageCategory.ER);
            }

            return(hierarchyItem);
        }
示例#11
0
        /// <summary>
        /// Returns the project in the solution,
        /// given a unique name.
        /// </summary>
        ///
        /// <param name="project">
        /// Full path to the solution project.
        /// </param>
        ///
        /// <returns>
        /// Pointer to the IVsHierarchy interface
        /// of the project referred to by project.
        /// </returns>
        ///
        /// <remarks>
        /// https://docs.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivshierarchy.
        /// </remarks>
        protected virtual IVsHierarchy GetProjectHierarchyItem(string project)
        {
            const int S_OK = 0;

            ThreadHelper.ThrowIfNotOnUIThread();

            int exitCode = VsSolution.GetProjectOfUniqueName(project, out IVsHierarchy hierarchyItem);

            if (exitCode != S_OK)
            {
                AddMessage($"Exit code: { exitCode }", TaskErrorCategory.Error);
            }

            return(hierarchyItem);
        }
示例#12
0
        public void PathPropertyReturnsInputFilePath()
        {
            // Arrange
            var solutionFileContent =
@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012";
            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);

            // Assert
            Assert.Equal(solutionFile, solution.Path);
        }
示例#13
0
        public void PathPropertyReturnsInputFilePath()
        {
            // Arrange
            var solutionFileContent =
                @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012";
            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);

            // Assert
            Assert.Equal(solutionFile, solution.Path);
        }
示例#14
0
        public void VsSolutionParserReadsWebsiteDetails(string solutionFileContent, string absolutePath)
        {
            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);
            var project  = solution.Projects.First();

            // Assert
            Assert.Equal("WebSite1", project.ProjectName);
            Assert.Empty(project.ProjectTypeGuids);
            Assert.Equal(absolutePath, project.AbsolutePath);
            Assert.False(project.IsWap);
            Assert.True(project.IsWebSite);
        }
示例#15
0
        /// <summary>Tries to open the solution. </summary>
        /// <param name="solution">The solution. </param>
        public void TryOpenSolution(VsSolution solution)
        {
            var title   = string.Format("Open solution '{0}'?", solution.Name);
            var message = string.Format("Open solution '{0}' at location \n{1}?", solution.Name, solution.Path);

            if (MessageBox.Show(message, title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                Process.Start(solution.Path);

                if (MinimizeWindowAfterSolutionLaunch)
                {
                    Application.Current.MainWindow.WindowState = WindowState.Minimized;
                }

                App.Telemetry.TrackEvent("OpenSolution");
            }
        }
示例#16
0
        private void UpdateUserSettings(ITextBuffer buffer, ITextSnapshot snapshot)
        {
            var sus = VsSolution.GetUserSettings();

            if (sus == null)
            {
                return;
            }
            String filename = TextEditor.GetFileName(buffer);

            if (String.IsNullOrEmpty(filename))
            {
                return;
            }
            filename = VsSolution.MakeRelativePath(filename);
            sus.Store(filename, Regions.GetStorableData(snapshot));
        }
示例#17
0
        public void VsSolutionParsesSolutionFile()
        {
            // Arrange
            var solutionFileContent =
@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Test"", ""Test\Test.csproj"", ""{80E5FD2A-A29A-47C7-8DE9-853D14295BAC}""
EndProject";

            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);

            // Assert
            Assert.Equal(1, solution.Projects.Count());
            Assert.Equal("Test", solution.Projects.First().ProjectName);
        }
示例#18
0
        public void VsSolutionParsesSolutionFile()
        {
            // Arrange
            var solutionFileContent =
                @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""Test"", ""Test\Test.csproj"", ""{80E5FD2A-A29A-47C7-8DE9-853D14295BAC}""
EndProject";

            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);

            // Assert
            Assert.Equal(1, solution.Projects.Count());
            Assert.Equal("Test", solution.Projects.First().ProjectName);
        }
示例#19
0
        private void Parse(string solutionFile, string[] skip)
        {
            VsSolution solution = VsSolution.Parse(File.ReadAllLines(solutionFile));

            string solutionPath = solutionFile;

            solutionPath = solutionPath.Remove(solutionPath.LastIndexOf('\\'));

            skip = TrimToLower(skip);

            List <ListBoxItemData> allFiles = new List <ListBoxItemData>();

            int  totalLines = 0;
            int  totalItems = 0;
            long totalSize  = 0;

            foreach (VsSolutionProjectPart each in solution.LinkedProjects)
            {
                if (!Contains(skip, each.Name.ToLower().Trim()))
                {
                    string projectPath = solutionPath + "\\" + each.Path;

                    if (File.Exists(projectPath))
                    {
                        VsProject proj = VsProject.Parse(projectPath.Remove(projectPath.LastIndexOf('\\')), File.ReadAllText(projectPath));
                        projectPath = projectPath.Remove(projectPath.LastIndexOf('\\'));

                        ProcessProject(allFiles, ref totalLines, ref totalItems, ref totalSize, each, projectPath, proj);
                    }
                }
            }

            Dispatcher.BeginInvoke(() =>
            {
                files.ItemsSource   = allFiles;
                skipBox.IsEnabled   = solutionPathBox.IsEnabled = browseButton.IsEnabled = parseButton.IsEnabled = true;
                parseButton.Content = "_Parse";
                lineCount.Text      = totalLines.ToString() + " line" + (totalLines != 1 ? "s" : "");
                itemCount.Text      = totalItems.ToString() + " item" + (totalItems != 1 ? "s" : "");
                itemSize.Text       = IOHelpers.FormatFileSize(totalSize);
            });
        }
示例#20
0
        private async Task LoadProjectsAsync()
        {
            ClearLoadedProjects();

            var errors = new Dictionary <string, Exception>();
            var tuple  = await RunTaskAsync(async() =>
            {
                var projectsTask  = VsProject.LoadAllFromDirectoryAsync(RootDirectory, IncludedProjectPathFilter, ExcludedProjectPathFilter, IgnoreExceptions, _projectCollection, errors);
                var solutionsTask = VsSolution.LoadAllFromDirectoryAsync(RootDirectory, IncludedProjectPathFilter, ExcludedProjectPathFilter, IgnoreExceptions, _projectCollection, errors);

                await Task.WhenAll(projectsTask, solutionsTask);
                await Task.Run(() =>
                {
                    var projectCache = projectsTask.Result.ToDictionary(p => p.Path, p => p);
                    foreach (var solution in solutionsTask.Result)
                    {
                        solution.LoadProjects(IgnoreExceptions, projectCache, errors);
                    }
                });

                return(new Tuple <List <VsProject>, List <VsSolution> >(projectsTask.Result, solutionsTask.Result));
            });

            if (tuple != null)
            {
                var projects  = tuple.Item1;
                var solutions = tuple.Item2;

                AllSolutions.Initialize(solutions.OrderBy(p => p.Name));
                AllProjects.Initialize(projects.OrderBy(p => p.Name));

                SelectedProject = FilteredProjects.FirstOrDefault();

                foreach (var error in errors)
                {
                    AddLog(error.Key + "\n" + error.Value.Message);
                }

                InitializeFilter();
                IsLoaded = true;
            }
        }
示例#21
0
        private VsSolution GetSolution(string solutionFolderPath, string applicationsPattern)
        {
            var      sln            = new VsSolution();
            var      solutionFolder = new DirectoryInfo(solutionFolderPath);
            var      solutionFiles  = solutionFolder.GetFiles().Where(x => x.Extension.Equals(".sln", StringComparison.OrdinalIgnoreCase)).ToList();
            FileInfo solutionFile   = null;

            if (solutionFiles.Count == 0)
            {
                return(sln);
            }
            else if (solutionFiles.Count == 1)
            {
                solutionFile = solutionFiles.First();
            }
            else
            {
                var found = false;
                foreach (var file in solutionFiles)
                {
                    if (solutionFolder.Name.IndexOf(file.Name.Replace(".sln", "")) > -1)
                    {
                        solutionFile = file;
                        found        = true;
                        break;
                    }
                }

                if (!found)
                {
                    solutionFile = solutionFiles.First();
                }
            }

            var applicationDetails = GetApplicationDetails(solutionFolderPath, solutionFile.FullName, applicationsPattern);

            sln.Name         = solutionFile.Name.Replace(".sln", "");
            sln.FolderName   = solutionFolder.Parent.Name;
            sln.Applications = applicationDetails;

            return(sln);
        }
        /// <summary>
        /// Initialize all Visual Studio Objects
        /// </summary>
        public void InitializeVsObjects()
        {
            Dte        = GetService(typeof(SDTE)) as DTE;
            Dte2       = GetService(typeof(SDTE)) as DTE2;
            VsSolution = GetService(typeof(SVsSolution)) as IVsSolution;

            if (Dte2 == null || Dte == null || VsSolution == null)
            {
                VsShell = GetService(typeof(SVsShell)) as IVsShell;
                _shellPropertyEventsHandler = new ShellPropertyEventsHandler(VsShell, InitializeVsObjects);
            }
            else
            {
                _shellPropertyEventsHandler = null;

                ToolWindowPane window = FindToolWindow(typeof(NAntRunnerToolWindow), 0, true);
                _solutionEventsHandler = new SolutionEventsHandler(window.Content as NAntRunnerToolWindowControl);
                VsSolution.AdviseSolutionEvents(_solutionEventsHandler, out _solutionEventsCookie);
            }
        }
示例#23
0
        private static RunStepResult TakeSolutionSnapshot(IRunExecutorHost host, RunStartParams rsp, RunStepInfo rsi)
        {
            var solutionGrandParentPath = Path.GetDirectoryName(Path.GetDirectoryName(rsp.Solution.Path.Item));
            var projects = VsSolution.GetProjects(host.HostVersion, rsp.Solution.Path.Item).ToList();

            var toCopy = new List <Tuple <string, SearchOption> >
            {
                new Tuple <string, SearchOption>(Path.GetDirectoryName(rsp.Solution.Path.Item), SearchOption.TopDirectoryOnly),
            };

            Array.ForEach(rsp.Config.SnapshotIncludeFolders,
                          item =>
            {
                toCopy.Add(new Tuple <string, SearchOption>(Path.Combine(Path.GetDirectoryName(rsp.Solution.Path.Item), item), SearchOption.AllDirectories));
            });

            projects.ForEach(p =>
            {
                var projectFile = Path.Combine(Path.GetDirectoryName(rsp.Solution.Path.Item), p.RelativePath);
                var folder      = Path.GetDirectoryName(projectFile);
                toCopy.Add(new Tuple <string, SearchOption>(folder, SearchOption.AllDirectories));
            });

            toCopy.ForEach(item =>
            {
                if (!host.CanContinue())
                {
                    throw new OperationCanceledException();
                }

                CopyFiles(rsp, solutionGrandParentPath, item.Item1, item.Item2);
            });

            SnapshotGC.mark(FilePath.NewFilePath(Path.GetDirectoryName(rsp.Solution.SnapshotPath.Item)));

            TelemetryClient.TrackEvent(rsi.name.Item, new Dictionary <string, string>(), new Dictionary <string, double> {
                { "ProjectCount", projects.Count }
            });

            return(RunStepStatus.Succeeded.ToRSR(RunData.NoData, "What was done - TBD"));
        }
示例#24
0
        private void LoadRegions(ITextBuffer buffer)
        {
            var sus = VsSolution.GetUserSettings();

            if (sus == null)
            {
                return;
            }
            String filename = TextEditor.GetFileName(buffer);

            if (String.IsNullOrEmpty(filename))
            {
                return;
            }
            filename = VsSolution.MakeRelativePath(filename);
            OutlineSettings settings = sus.Load <OutlineSettings>(filename);

            if (settings != null)
            {
                this.Regions.LoadStoredData(buffer.CurrentSnapshot, settings);
            }
        }
示例#25
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository)
        {
            string repositoryRoot = repository.RepositoryPath;

            // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules
            var fileFinder = new CachedVsProjectsFileFinder(repository);

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the user provided specific generator arguments, that overrides any detection logic
            string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs);

            if (!String.IsNullOrEmpty(scriptGeneratorArgs))
            {
                return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);
                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));
            }

            if (settings.RunFromLocalZip())
            {
                return(new RunFromZipSiteBuilder());
            }

            if (!settings.DoBuildDuringDeployment())
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
            }

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    return(new DotNetConsoleBuilder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                return(new AspNetCoreBuilder(_environment,
                                             settings,
                                             _propertyProvider,
                                             repositoryRoot,
                                             project.AbsolutePath,
                                             solution.Path));
            }

            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            return(new FunctionMsbuildBuilder(_environment,
                                              settings,
                                              _propertyProvider,
                                              repositoryRoot,
                                              project.AbsolutePath,
                                              solution.Path));
        }
示例#26
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository, DeploymentInfoBase deploymentInfo)
        {
            string repositoryRoot = repository.RepositoryPath;

            // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules
            var fileFinder = new CachedVsProjectsFileFinder(repository);

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the user provided specific generator arguments, that overrides any detection logic
            string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs);

            if (!String.IsNullOrEmpty(scriptGeneratorArgs))
            {
                return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);
                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));
            }

            if (deploymentInfo != null && deploymentInfo.Deployer == Constants.OneDeploy)
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new OneDeployBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath, deploymentInfo));
            }

            if (settings.RunFromLocalZip())
            {
                return(new RunFromZipSiteBuilder());
            }

            if (!settings.DoBuildDuringDeployment())
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
            }

            string msbuild16Log = String.Format("UseMSBuild16: {0}", VsHelper.UseMSBuild16().ToString());

            tracer.Trace(msbuild16Log);
            KuduEventSource.Log.GenericEvent(
                ServerConfiguration.GetRuntimeSiteName(),
                msbuild16Log,
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty
                );

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            return(DetermineProjectFromSolution(logger, settings, repository, solution));
        }
示例#27
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IFileFinder fileFinder)
        {
            string repositoryRoot = _environment.RepositoryPath;

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);

                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));

                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite).FirstOrDefault();

            if (project == null)
            {
                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            return(new WebSiteBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
        }
 public PackageSolutionDetailControlModel(
     VsSolution solution,
     UiSearchResultPackage searchResultPackage) :
     base(solution, searchResultPackage)
 {
 }
示例#29
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger, IDeploymentSettingsManager settings, IRepository repository, DeploymentInfoBase deploymentInfo)
        {
            string repositoryRoot = repository.RepositoryPath;

            // Use the cached vs projects file finder for: a. better performance, b. ignoring solutions/projects under node_modules
            var fileFinder = new CachedVsProjectsFileFinder(repository);

            // If there's a custom deployment file then let that take over.
            var command = settings.GetValue(SettingsKeys.Command);

            if (!String.IsNullOrEmpty(command))
            {
                return(new CustomBuilder(_environment, settings, _propertyProvider, repositoryRoot, command));
            }

            // If the user provided specific generator arguments, that overrides any detection logic
            string scriptGeneratorArgs = settings.GetValue(SettingsKeys.ScriptGeneratorArgs);

            if (!String.IsNullOrEmpty(scriptGeneratorArgs))
            {
                return(new CustomGeneratorCommandSiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, scriptGeneratorArgs));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = settings.GetValue(SettingsKeys.Project);

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Specific project was specified: " + targetProjectPath);
                targetProjectPath = Path.GetFullPath(Path.Combine(repositoryRoot, targetProjectPath.TrimStart('/', '\\')));
            }

            if (deploymentInfo != null && deploymentInfo.Deployer == Constants.OneDeploy)
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new OneDeployBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath, deploymentInfo));
            }

            if (settings.RunFromLocalZip())
            {
                return(new RunFromZipSiteBuilder());
            }

            if (!settings.DoBuildDuringDeployment())
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                if (DeploymentHelper.IsDeploymentV2Request())
                {
                    return(new DeploymentV2Builder(_environment, settings, _propertyProvider, repositoryRoot));
                }
                else
                {
                    return(new BasicBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
                }
            }

            // Check if we really need a builder for this
            // If not, return the NoOpBuilder
            string appFramework = System.Environment.GetEnvironmentVariable("FRAMEWORK");

            if (!string.IsNullOrEmpty(appFramework) && string.Equals(appFramework, "STATICSITE", StringComparison.OrdinalIgnoreCase))
            {
                var projectPath = !String.IsNullOrEmpty(targetProjectPath) ? targetProjectPath : repositoryRoot;
                return(new NoOpBuilder(_environment, settings, _propertyProvider, repositoryRoot, projectPath));
            }

            // If ENABLE_ORYX_BUILD is not set, for function app, we assume it on by default
            string enableOryxBuild = System.Environment.GetEnvironmentVariable("ENABLE_ORYX_BUILD");

            if (!string.IsNullOrEmpty(enableOryxBuild))
            {
                if (StringUtils.IsTrueLike(enableOryxBuild))
                {
                    return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot));
                }
            }
            else if (FunctionAppHelper.LooksLikeFunctionApp())
            {
                return(new OryxBuilder(_environment, settings, _propertyProvider, repositoryRoot));
            }

            string framework = System.Environment.GetEnvironmentVariable("FRAMEWORK");

            if (framework.Equals("ruby", StringComparison.OrdinalIgnoreCase))
            {
                return(new RubySiteBuilder(_environment, settings, _propertyProvider, repositoryRoot, targetProjectPath));
            }

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      settings,
                                      fileFinder,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot, fileFinder).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      settings,
                                      fileFinder,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    return(new DotNetConsoleBuilder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                return(new AspNetCoreBuilder(_environment,
                                             settings,
                                             _propertyProvider,
                                             repositoryRoot,
                                             project.AbsolutePath,
                                             solution.Path));
            }

            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            return(new FunctionMsbuildBuilder(_environment,
                                              settings,
                                              _propertyProvider,
                                              repositoryRoot,
                                              project.AbsolutePath,
                                              solution.Path));
        }
示例#30
0
        public void VsSolutionParserReadsWebsiteDetails(string solutionFileContent, string absolutePath)
        {
            var solutionFile = CreateSolutionFile(solutionFileContent);

            // Act
            var solution = new VsSolution(solutionFile);
            var project = solution.Projects.First();

            // Assert
            Assert.Equal("WebSite1", project.ProjectName);
            Assert.Empty(project.ProjectTypeGuids);
            Assert.Equal(absolutePath, project.AbsolutePath);
            Assert.False(project.IsWap);
            Assert.True(project.IsWebSite);
        }
示例#31
0
        private ISiteBuilder DetermineProjectFromSolution(ILogger logger, IDeploymentSettingsManager settings, IRepository repository, VsSolution solution)
        {
            string repositoryRoot = repository.RepositoryPath;

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            // shunTODO need to implement this
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite || p.IsAspNetCore || p.IsFunctionApp).FirstOrDefault();

            if (project == null)
            {
                // Try executable type project
                project = solution.Projects.Where(p => p.IsExecutable).FirstOrDefault();
                if (project != null)
                {
                    if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
                    {
                        return(new DotNetConsoleMSBuild1607Builder(_environment,
                                                                   settings,
                                                                   _propertyProvider,
                                                                   repositoryRoot,
                                                                   project.AbsolutePath,
                                                                   solution.Path));
                    }
                    else if (VsHelper.UseMSBuild16())
                    {
                        return(new DotNetCoreConsoleMSBuild16Builder(_environment,
                                                                     settings,
                                                                     _propertyProvider,
                                                                     repositoryRoot,
                                                                     project.AbsolutePath,
                                                                     solution.Path));
                    }
                    else
                    {
                        return(new DotNetConsoleBuilder(_environment,
                                                        settings,
                                                        _propertyProvider,
                                                        repositoryRoot,
                                                        project.AbsolutePath,
                                                        solution.Path));
                    }
                }

                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                // we have a solution file, but no deployable project
                // shunTODO how often do we run into this
                return(ResolveNonAspProject(repositoryRoot, null, settings));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_environment,
                                      settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      solution.Path));
            }

            if (project.IsAspNetCore)
            {
                if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
                {
                    return(new AspNetCoreMSBuild1607Builder(_environment,
                                                            settings,
                                                            _propertyProvider,
                                                            repositoryRoot,
                                                            project.AbsolutePath,
                                                            solution.Path));
                }
                else if (VsHelper.UseMSBuild16())
                {
                    return(new AspNetCoreMSBuild16Builder(_environment,
                                                          settings,
                                                          _propertyProvider,
                                                          repositoryRoot,
                                                          project.AbsolutePath,
                                                          solution.Path));
                }
                else
                {
                    return(new AspNetCoreBuilder(_environment,
                                                 settings,
                                                 _propertyProvider,
                                                 repositoryRoot,
                                                 project.AbsolutePath,
                                                 solution.Path));
                }
            }


            if (project.IsWebSite)
            {
                return(new WebSiteBuilder(_environment,
                                          settings,
                                          _propertyProvider,
                                          repositoryRoot,
                                          project.AbsolutePath,
                                          solution.Path));
            }

            if (VsHelper.UseMSBuild1607() || VsHelper.IsDotNetCore5(project.TargetFramework))
            {
                return(new FunctionMSBuild1607Builder(_environment,
                                                      settings,
                                                      _propertyProvider,
                                                      repositoryRoot,
                                                      project.AbsolutePath,
                                                      solution.Path));
            }
            else if (VsHelper.UseMSBuild16())
            {
                return(new FunctionMSBuild16Builder(_environment,
                                                    settings,
                                                    _propertyProvider,
                                                    repositoryRoot,
                                                    project.AbsolutePath,
                                                    solution.Path));
            }
            else
            {
                return(new FunctionMsbuildBuilder(_environment,
                                                  settings,
                                                  _propertyProvider,
                                                  repositoryRoot,
                                                  project.AbsolutePath,
                                                  solution.Path));
            }
        }
示例#32
0
        public ISiteBuilder CreateBuilder(ITracer tracer, ILogger logger)
        {
            string repositoryRoot = _environment.RepositoryPath;
            var    configuration  = new DeploymentConfiguration(repositoryRoot);

            // If there's a custom deployment file then let that take over.
            if (!String.IsNullOrEmpty(configuration.Command))
            {
                return(new CustomBuilder(repositoryRoot, _environment.TempPath, configuration.Command, _propertyProvider, _environment.SiteRootPath));
            }

            // If the repository has an explicit pointer to a project path to be deployed
            // then use it.
            string targetProjectPath = configuration.ProjectPath;

            if (!String.IsNullOrEmpty(targetProjectPath))
            {
                tracer.Trace("Found .deployment file in repository");

                // Try to resolve the project
                return(ResolveProject(repositoryRoot,
                                      targetProjectPath,
                                      tryWebSiteProject: true,
                                      searchOption: SearchOption.TopDirectoryOnly));
            }

            // Get all solutions in the current repository path
            var solutions = VsHelper.GetSolutions(repositoryRoot).ToList();

            if (!solutions.Any())
            {
                return(ResolveProject(repositoryRoot,
                                      searchOption: SearchOption.AllDirectories));
            }

            // More than one solution is ambiguous
            if (solutions.Count > 1)
            {
                // TODO: Show relative paths in error messages
                ThrowAmbiguousSolutionsError(solutions);
            }

            // We have a solution
            VsSolution solution = solutions[0];

            // We need to determine what project to deploy so get a list of all web projects and
            // figure out with some heuristic, which one to deploy.

            // TODO: Pick only 1 and throw if there's more than one
            VsSolutionProject project = solution.Projects.Where(p => p.IsWap || p.IsWebSite).FirstOrDefault();

            if (project == null)
            {
                logger.Log(Resources.Log_NoDeployableProjects, solution.Path);

                return(new BasicBuilder(repositoryRoot, _environment.TempPath, _environment.ScriptPath, _environment.SiteRootPath));
            }

            if (project.IsWap)
            {
                return(new WapBuilder(_settings,
                                      _propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      _environment.TempPath,
                                      _environment.NuGetCachePath,
                                      solution.Path));
            }

            return(new WebSiteBuilder(_propertyProvider,
                                      repositoryRoot,
                                      project.AbsolutePath,
                                      _environment.TempPath,
                                      _environment.NuGetCachePath,
                                      solution.Path));
        }
示例#33
0
 void CreateVsSolution()
 {
     fakeProjectService = new FakePackageManagementProjectService();
     solution           = new VsSolution(fakeProjectService);
 }
 public PackageSolutionDetailControlModel(
     VsSolution solution,
     UiSearchResultPackage searchResultPackage) :
     base(solution, searchResultPackage)
 {
 }