public void AddProjectsToSolutionExplorer(Folder root, IEnumerable <Project> projects)
        {
            if (!ProjectFilePath.EndsWith(".sln", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            Dictionary <string, IEnumerable <string> > projectToSolutionFolderMap = null;

            if (!Configuration.FlattenSolutionExplorer)
            {
                projectToSolutionFolderMap = GetProjectToSolutionFolderMap(ProjectFilePath);
            }

            var processedAssemblyNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            foreach (var project in projects)
            {
                if (!processedAssemblyNames.Add(project.AssemblyName))
                {
                    // filter out multiple projects with the same assembly name
                    continue;
                }

                if (Configuration.FlattenSolutionExplorer)
                {
                    AddProjectToFolder(root, project);
                }
                else
                {
                    AddProjectToFolder(root, project, projectToSolutionFolderMap);
                }
            }
        }
        /// Note: currently no need for this capability.
        public static PackageSpecification[] GetPackageReferences(ProjectFilePath projectFilePath)
        {
            var packageSpecifications = new List <PackageSpecification>();

            // dotnet list package output is too complicated to parse, so just go direct to XML.
            var doc = new XmlDocument();

            doc.Load(projectFilePath.Value);

            var nodes = doc.SelectNodes("//Project/ItemGroup/PackageReference");

            for (int iNode = 0; iNode < nodes.Count; iNode++)
            {
                var node = nodes.Item(iNode);

                var includeAttribute = node.Attributes["Include"];
                var versionAttribute = node.Attributes["Version"];

                var packageID      = includeAttribute.Value.AsPackageID();
                var packageVersion = Version.Parse(versionAttribute.Value);

                var packageSpecification = new PackageSpecification(packageID, packageVersion);
                packageSpecifications.Add(packageSpecification);
            }

            var output = packageSpecifications.ToArray();

            return(output);
        }
Ejemplo n.º 3
0
        public override bool WriteProjectFile(List <UnrealTargetPlatform> InPlatforms, List <UnrealTargetConfiguration> InConfigurations)
        {
            bool bSuccess = false;

            string TargetName = ProjectFilePath.GetFileNameWithoutExtension();

            FileReference GameProjectPath = null;

            foreach (ProjectTarget Target in ProjectTargets)
            {
                if (Target.UnrealProjectFilePath != null)
                {
                    GameProjectPath = Target.UnrealProjectFilePath;
                    break;
                }
            }

            StringBuilder ProjectFileContent = new StringBuilder();

            ProjectFileContent.Append("# @Eddie Workset@" + ProjectFileGenerator.NewLine);
            ProjectFileContent.Append("AddWorkset \"" + this.ToString() + ".wkst\" \"" + ProjectFilePath.FullName + "\"" + ProjectFileGenerator.NewLine);

            ParseSourceFilesIntoGroups();
            EmitProject(ProjectFileContent, Folders);

            bSuccess = ProjectFileGenerator.WriteFileIfChanged(ProjectFilePath.FullName, ProjectFileContent.ToString(), new UTF8Encoding());

            return(bSuccess);
        }
Ejemplo n.º 4
0
        public void SetProjectVersion(ProjectFilePath projectFilePath, Version version)
        {
            var versionStringForDisplay     = version.ToString();
            var versionStringForProjectFile = version.ToString();

            this.Logger.LogDebug($"{projectFilePath} - Setting project file version:\n{versionStringForDisplay}");

            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Determine if there is a Project/PropertyGroup/Version node.
            var versionNodeXPath = "//Project/PropertyGroup/Version";
            var versionNode      = xmlDoc.SelectSingleNode(versionNodeXPath);

            if (versionNode == null)
            {
                // Create the new node.
                versionNode = xmlDoc.CreateElement("Version");
            }

            versionNode.InnerText = versionStringForProjectFile;

            // Find the first PropertyGroup node.
            var projectPropertyGroupNodeXPath = "//Project/PropertyGroup";
            var projectPropertyGroupNode      = xmlDoc.SelectSingleNode(projectPropertyGroupNodeXPath);

            projectPropertyGroupNode.AppendChild(versionNode);

            xmlDoc.Save(projectFilePath.Value);

            this.Logger.LogInformation($"{projectFilePath} - Set project file version:\n{versionStringForDisplay}");
        }
Ejemplo n.º 5
0
        public void SuppressMissingXmlDocumentationWarnings(ProjectFilePath projectFilePath)
        {
            this.Logger.LogDebug($"{projectFilePath} - Suppressing missing XML documentation warning.");

            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Modify the project file.
            var noWarnElementXPath = "//Project/PropertyGroup/NoWarn";
            var noWarnElement      = xmlDoc.SelectSingleNode(noWarnElementXPath);

            if (null == noWarnElement)
            {
                var propertyGroupElementXPath = "//Project/PropertyGroup";
                var propertyGroupElement      = xmlDoc.SelectSingleNode(propertyGroupElementXPath);

                noWarnElement = xmlDoc.CreateElement("NoWarn");
                propertyGroupElement.AppendChild(noWarnElement);
            }

            noWarnElement.InnerText = "1701;1702;1591;1573"; // NOTE! MUST include 1701 and 1702. These are required for .NET Core, and are included by default in the project template. However, explicitly setting any NoWarn property value will override the project template. Thus, we must include these warning in the list of suppressions.

            // Save the project file.
            xmlDoc.Save(projectFilePath.Value);

            this.Logger.LogInformation($"{projectFilePath} - Suppressed missing XML documentation warning.");
        }
Ejemplo n.º 6
0
        public void EnableDocumentationGeneration(ProjectFilePath projectFilePath)
        {
            this.Logger.LogDebug($"{projectFilePath} - Enabling documentation generation.");

            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Modify the project file.
            var generateDocumentationFileElementXPath = "//Project/PropertyGroup/GenerateDocumentationFile";
            var generateDocumentationFileElement      = xmlDoc.SelectSingleNode(generateDocumentationFileElementXPath);

            if (null == generateDocumentationFileElement)
            {
                var propertyGroupElementXPath = "//Project/PropertyGroup";
                var propertyGroupElement      = xmlDoc.SelectSingleNode(propertyGroupElementXPath);

                generateDocumentationFileElement = xmlDoc.CreateElement("GenerateDocumentationFile");
                propertyGroupElement.AppendChild(generateDocumentationFileElement);
            }

            generateDocumentationFileElement.InnerText = "true";

            // Save the project file.
            xmlDoc.Save(projectFilePath.Value);

            this.Logger.LogInformation($"{projectFilePath} - Enabled documentation generation.");
        }
Ejemplo n.º 7
0
        public static void SetVersion(ProjectFilePath projectFilePath, Version version)
        {
            var versionString = version.ToString();

            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Determine if there is a Project/PropertyGroup/Version node.
            var versionNodeXPath = "//Project/PropertyGroup/Version";
            var versionNode      = xmlDoc.SelectSingleNode(versionNodeXPath);

            var hasVersion = versionNode != null;

            if (!hasVersion)
            {
                var propertyGroupXPath = "//Project/PropertyGroup";
                var propertyGroupNode  = xmlDoc.SelectSingleNode(propertyGroupXPath);

                versionNode = xmlDoc.CreateElement("Version");
                propertyGroupNode.AppendChild(versionNode);
            }

            versionNode.InnerText = versionString;

            xmlDoc.Save(projectFilePath.Value);
        }
Ejemplo n.º 8
0
        public override bool WriteProjectFile(List <UnrealTargetPlatform> InPlatforms, List <UnrealTargetConfiguration> InConfigurations)
        {
            bool bSuccess = false;

            var TargetName = ProjectFilePath.GetFileNameWithoutExtension();

            FileReference             GameProjectPath = null;
            List <DirectoryReference> GameFolders     = UEBuildTarget.DiscoverAllGameFolders();

            foreach (var GameFolder in GameFolders)
            {
                FileReference UProjectPath = FileReference.Combine(GameFolder, TargetName + ".uproject");
                if (FileReference.Exists(UProjectPath))
                {
                    GameProjectPath = UProjectPath;
                    break;
                }
            }

            var ProjectFileContent = new StringBuilder();

            ProjectFileContent.Append("# @Eddie Workset@" + ProjectFileGenerator.NewLine);
            ProjectFileContent.Append("AddWorkset \"" + this.ToString() + ".wkst\" \"" + ProjectFilePath.FullName + "\"" + ProjectFileGenerator.NewLine);

            ParseSourceFilesIntoGroups();
            EmitProject(ProjectFileContent, Folders);

            bSuccess = ProjectFileGenerator.WriteFileIfChanged(ProjectFilePath.FullName, ProjectFileContent.ToString(), new UTF8Encoding());

            return(bSuccess);
        }
Ejemplo n.º 9
0
        public static ProjectName GetProjectName(ProjectFilePath projectFilePath)
        {
            var projectFileName = PathUtilities.GetFileName(projectFilePath).AsProjectFileName();

            var projectName = Utilities.GetProjectName(projectFileName);

            return(projectName);
        }
Ejemplo n.º 10
0
        public static PackageID GetDefaultPackageID(ProjectFilePath projectFilePath)
        {
            var projectFileName = VsIoUtilities.GetProjectFileName(projectFilePath);

            var packageID = Utilities.GetDefaultPackageID(projectFileName);

            return(packageID);
        }
        public static NupkgFilePath Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, DirectoryPath outputDirectoryPath, ILogger logger)
        {
            // Determine the package ID.
            var packageID = NugetUtilities.GetDefaultPackageID(projectFilePath);

            var packageFilePath = DotnetCommandServicesProvider.Pack(dotnetExecutableFilePath, projectFilePath, outputDirectoryPath, packageID, Enumerable.Empty <string>(), logger);

            return(packageFilePath);
        }
Ejemplo n.º 12
0
        public string GetTangerineCacheBundlePath()
        {
            var name = string
                       .Join("_", ProjectFilePath.Split(new[] { "\\", "/", ":" }, StringSplitOptions.RemoveEmptyEntries))
                       .ToLower(System.Globalization.CultureInfo.InvariantCulture);

            name = Path.ChangeExtension(name, "tancache");
            return(Path.Combine(WorkspaceConfig.GetDataPath(), name));
        }
        public static void AddProjectFileProjectReference(ProjectFilePath projectFilePath, ProjectFilePath referenceProjectFilePath, ILogger logger)
        {
            logger.LogDebug($"{projectFilePath} - Adding reference to project file:\n{referenceProjectFilePath}");

            var arguments = $@"add ""{projectFilePath}"" reference ""{referenceProjectFilePath}""";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"{projectFilePath} - Added reference to project file:\n{referenceProjectFilePath}");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Write project file info in JSON file.
        /// For every combination of <c>UnrealTargetPlatform</c>, <c>UnrealTargetConfiguration</c> and <c>TargetType</c>
        /// will be generated separate JSON file.
        /// Project file will be stored:
        /// For UE4:  {UE4Root}/Engine/Intermediate/ProjectFiles/.Rider/{Platform}/{Configuration}/{TargetType}/{ProjectName}.json
        /// For game: {GameRoot}/Intermediate/ProjectFiles/.Rider/{Platform}/{Configuration}/{TargetType}/{ProjectName}.json
        /// </summary>
        /// <remarks>
        /// * <c>UnrealTargetPlatform.Win32</c> will be always ignored.
        /// * <c>TargetType.Editor</c> will be generated for current platform only and will ignore <c>UnrealTargetConfiguration.Test</c> and <c>UnrealTargetConfiguration.Shipping</c> configurations
        /// * <c>TargetType.Program</c>  will be generated for current platform only and <c>UnrealTargetConfiguration.Development</c> configuration only
        /// </remarks>
        /// <param name="InPlatforms"></param>
        /// <param name="InConfigurations"></param>
        /// <param name="PlatformProjectGenerators"></param>
        /// <returns></returns>
        public override bool WriteProjectFile(List <UnrealTargetPlatform> InPlatforms,
                                              List <UnrealTargetConfiguration> InConfigurations,
                                              PlatformProjectGeneratorCollection PlatformProjectGenerators)
        {
            string             ProjectName       = ProjectFilePath.GetFileNameWithoutAnyExtensions();
            DirectoryReference projectRootFolder = DirectoryReference.Combine(RootPath, ".Rider");
            List <Tuple <FileReference, UEBuildTarget> > fileToTarget = new List <Tuple <FileReference, UEBuildTarget> >();

            foreach (UnrealTargetPlatform Platform in InPlatforms.Where(it => it != UnrealTargetPlatform.Win32))
            {
                foreach (UnrealTargetConfiguration Configuration in InConfigurations)
                {
                    foreach (ProjectTarget ProjectTarget in ProjectTargets)
                    {
                        if (TargetTypes.Any() && !TargetTypes.Contains(ProjectTarget.TargetRules.Type))
                        {
                            continue;
                        }

                        // Skip Programs for all configs except for current platform + Development configuration
                        if (ProjectTarget.TargetRules.Type == TargetType.Program && (BuildHostPlatform.Current.Platform != Platform || Configuration != UnrealTargetConfiguration.Development))
                        {
                            continue;
                        }

                        // Skip Editor for all platforms except for current platform
                        if (ProjectTarget.TargetRules.Type == TargetType.Editor && (BuildHostPlatform.Current.Platform != Platform || (Configuration == UnrealTargetConfiguration.Test || Configuration == UnrealTargetConfiguration.Shipping)))
                        {
                            continue;
                        }

                        DirectoryReference ConfigurationFolder = DirectoryReference.Combine(projectRootFolder, Platform.ToString(), Configuration.ToString());

                        DirectoryReference TargetFolder =
                            DirectoryReference.Combine(ConfigurationFolder, ProjectTarget.TargetRules.Type.ToString());

                        string DefaultArchitecture = UEBuildPlatform
                                                     .GetBuildPlatform(BuildHostPlatform.Current.Platform)
                                                     .GetDefaultArchitecture(ProjectTarget.UnrealProjectFilePath);
                        TargetDescriptor TargetDesc = new TargetDescriptor(ProjectTarget.UnrealProjectFilePath, ProjectTarget.Name,
                                                                           BuildHostPlatform.Current.Platform, UnrealTargetConfiguration.Development,
                                                                           DefaultArchitecture, Arguments);
                        UEBuildTarget BuildTarget = UEBuildTarget.Create(TargetDesc, false, false);
                        FileReference OutputFile  = FileReference.Combine(TargetFolder, $"{ProjectName}.json");
                        fileToTarget.Add(Tuple.Create(OutputFile, BuildTarget));
                    }
                }
            }
            foreach (Tuple <FileReference, UEBuildTarget> tuple in fileToTarget)
            {
                SerializeTarget(tuple.Item1, tuple.Item2);
            }

            return(true);
        }
Ejemplo n.º 15
0
 public override int GetHashCode()
 {
     return
         (AssemblyNumber.GetHashCode() ^
          ProjectFilePath.GetHashCode() ^
          Glyph.GetHashCode() ^
          Name.GetHashCode() ^
          Kind.GetHashCode() ^
          Description.GetHashCode() ^
          ID.GetHashCode());
 }
        public static void AddPackageToProject(ProjectFilePath projectFilePath, PackageSpecification packageSpecification, ILogger logger)
        {
            logger.LogDebug($"{projectFilePath} - Adding package to project file:\n{packageSpecification}");

            var packageArgument = " " + $"package {packageSpecification.ID}";
            var versionArgument = packageSpecification.HasVersion() ? " " + $"--version {packageSpecification.Version}" : String.Empty;
            var arguments       = $@"add ""{projectFilePath}""{packageArgument}{versionArgument}";

            ProcessRunner.Run(DotnetCommand.Value, arguments);

            logger.LogInformation($"{projectFilePath} - Added package to project file:\n{packageSpecification}");
        }
        public static void Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, NupkgFilePath nupkgFilePath, ILogger logger)
        {
            var packageDirectoryPath = PathUtilities.GetDirectoryPath(nupkgFilePath);

            // Use the pack command to get the package file-path created by dotnet.
            var defaultPackageFilePath = DotnetCommandServicesProvider.Pack(dotnetExecutableFilePath, projectFilePath, packageDirectoryPath, logger);

            // If the package file-path created by dotnet is not the same as the specified package file-path, copy the file to the new path.
            if (nupkgFilePath.Value != defaultPackageFilePath.Value)
            {
                File.Copy(defaultPackageFilePath.Value, nupkgFilePath.Value, true);
                File.Delete(defaultPackageFilePath.Value);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Manipulates the files.
        /// </summary>
        /// <returns>The path to the project file</returns>
        private string GetNewProjectFile()
        {
            string tempPath = string.Empty;
            // string k2DeployFolder = string.Empty;
            FileHelper fileHelper = new FileHelper();

            //Get the project folder
            string projectFolder = fileHelper.GetFolderFromPath(ProjectFilePath);

            LogHelper.LogMessage("      Project Folder: " + projectFolder);

            // Get the Project File Path
            string projectFile = fileHelper.GetFileNameFromPath(ProjectFilePath);

            LogHelper.LogMessage("      Project File: " + projectFile);

            LogHelper.LogMessage("   -- Getting path to a temporary folder for the K2 project files");
            tempPath = fileHelper.GetTempDirectory();

            TempDeployFolderPath = tempPath + @"\K2Deploy";

            LogHelper.LogMessage("      Temp Folder: " + TempDeployFolderPath);
            LogHelper.LogMessage("   -- Cleaning up files from any previous builds");
            fileHelper.DeleteDirectory(TempDeployFolderPath);

            LogHelper.LogMessage("   -- Copying files to the temp folder");
            fileHelper.CopyFolder(projectFolder, TempDeployFolderPath);
            LogHelper.LogMessage("      Files copied from '" + projectFolder + "' to '" + TempDeployFolderPath + "'");

            //Ensure we have access to all the files.
            LogHelper.LogMessage("   -- Setting ACL on folders and files in '" + TempDeployFolderPath + "'");
            bool success = fileHelper.SetAcl(TempDeployFolderPath, "F", true);

            if (!success)
            {
                throw new Exception("Failed to set ACLs on folder " + TempDeployFolderPath);
            }

            //Ensure the files are all writable
            LogHelper.LogMessage("   -- Setting writable permissions for folder: " + TempDeployFolderPath);
            fileHelper.SetWritable(TempDeployFolderPath);

            LogHelper.LogMessage("   -- Getting the Project File Path in Temp Folder");
            string newProjectFilePath = TempDeployFolderPath + @"\" + ProjectFilePath.Substring(1 + ProjectFilePath.LastIndexOf('\\'));

            LogHelper.LogMessage("      New Project File: " + newProjectFilePath);

            return(newProjectFilePath);
        }
        public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, DotnetNewConventions conventions, ILogger logger)
        {
            var projectDirectoryPath            = PathUtilities.GetDirectoryPath(projectFilePath).AsProjectDirectoryPath();
            var projectFileName                 = PathUtilities.GetFileName(projectFilePath).AsProjectFileName();
            var projectFileNameWithoutExtension = PathUtilities.GetFileNameWithoutExtension(projectFileName);
            var projectName = conventions.ProjectNameFromProjectFileNameWithoutExtension(projectFileNameWithoutExtension);

            var createdProjectFilePath = DotnetCommandServicesProvider.CreateProjectFile(projectType, projectName, projectDirectoryPath, logger);

            // Throw an exception if the solution file-path created by dotnet new is not the one we were expecting.
            if (createdProjectFilePath.Value != projectFilePath.Value)
            {
                throw new Exception($"Project creation file path mismatch.\nExpected: {projectFilePath}\nCreated: {createdProjectFilePath}");
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Validates the K2 project.
        /// </summary>
        private void ValidateK2Project()
        {
            // Make sure that it's a K2 project
            if (!ProjectFilePath.EndsWith(".k2proj"))
            {
                throw new ArgumentException("Project file must end with .k2proj.\n");
            }

            // If not using the local environment cache then make sure that credentials are available
            if (!UseEnvironmentCache &&
                (string.IsNullOrEmpty(WindowsDomain) ||
                 string.IsNullOrEmpty(WindowsUsername) ||
                 string.IsNullOrEmpty(WindowsPassword)))
            {
                throw new ArgumentException("Valid User credentials must be entered if not using local Environment cache.\n");
            }
        }
        public static ProjectFilePath[] GetProjectReferencedProjectFilePaths(ProjectFilePath projectFilePath)
        {
            // Get all project file paths that are referenced by the solution file path.
            var arguments = $@"list ""{projectFilePath}"" reference";

            var projectFilePaths = new List <ProjectFilePath>();

            var runOptions = new ProcessRunOptions
            {
                Command           = DotnetCommand.Value,
                Arguments         = arguments,
                ReceiveOutputData = (sender, e) => DotnetCommandServicesProvider.ProcessListProjectProjectReferencesOutput(sender, e, projectFilePath, projectFilePaths),
            };

            ProcessRunner.Run(runOptions);

            return(projectFilePaths.ToArray());
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Evaluates the given Scripty scripts
        /// </summary>
        /// <param name="scriptFiles">The script files to evaluate</param>
        public void Evaluate(IEnumerable <FilePath> scriptFiles)
        {
            var filePaths = scriptFiles as IList <FilePath> ?? scriptFiles.ToList();

            if (!filePaths.Any())
            {
                throw new ArgumentException("No files provided to evaluate", nameof(scriptFiles));
            }
            var args = new ProcessArgumentBuilder();

            args.AppendQuoted(ProjectFilePath.MakeAbsolute(Environment).FullPath);
            foreach (var scriptFile in filePaths)
            {
                var path = ProjectFilePath.MakeAbsolute(Environment).GetRelativePath(scriptFile.MakeAbsolute(Environment)).FullPath;
                args.AppendQuoted(path);
            }
            Run(Settings, args);
        }
Ejemplo n.º 23
0
        public void SetFileCopyToOutputDirectory(ProjectFilePath projectFilePath, FilePath filePath)
        {
            var fileProjectFileRelativePath = PathUtilities.GetRelativePath(projectFilePath.Value, filePath.Value);

            this.Logger.LogDebug($"{projectFilePath} - Setting copy to output directory for file:\n{fileProjectFileRelativePath}");

            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Create the new node.
            var copyToOutputDirectoryNode = xmlDoc.CreateElement("CopyToOutputDirectory");

            copyToOutputDirectoryNode.InnerText = "PreserveNewest";

            var noneNode = xmlDoc.CreateElement("None");

            noneNode.AppendChild(copyToOutputDirectoryNode);

            var updateAttributeNode = xmlDoc.CreateAttribute("Update");

            updateAttributeNode.Value = fileProjectFileRelativePath;
            noneNode.Attributes.Append(updateAttributeNode);

            var itemGroupNode = xmlDoc.CreateElement("ItemGroup");

            itemGroupNode.AppendChild(noneNode);

            var projectNode = xmlDoc.ChildNodes[0];

            var firstItemGroup = projectNode.ChildNodes[0];

            projectNode.InsertAfter(itemGroupNode, firstItemGroup);

            xmlDoc.Save(projectFilePath.Value);

            this.Logger.LogInformation($"{projectFilePath} - Set copy to output directory for file:\n{fileProjectFileRelativePath}");
        }
        public static NupkgFilePath Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, DirectoryPath outputDirectoryPath, PackageID packageID, IEnumerable <string> sources, ILogger logger)
        {
            // Determine the project version.
            var projectVersion = VsUtilities.GetVersion(projectFilePath);

            var packageFileName = NugetIoUtilities.GetNupkgFileName(packageID, projectVersion);

            // Determine the .nupkg file-name and file-path (using output directory-path, project ID, project version, and .nupkg file-extension).
            var packageFilePath = PathUtilitiesExtra.GetFilePath(outputDirectoryPath, packageFileName).AsNupkgFilePath();

            logger.LogDebug($"{projectFilePath} - Packing project to:\n{packageFilePath}");

            var arguments = $@"pack ""{projectFilePath}"" --output ""{outputDirectoryPath}"" -p:PackageID={packageID}";

            if (sources.Count() > 0)
            {
                foreach (var source in sources)
                {
                    arguments = arguments.Append($@" --source ""{source}""");
                }
            }

            var outputCollector = ProcessRunner.Run(dotnetExecutableFilePath.Value, arguments);

            // Test for success.
            var lastLine = outputCollector.GetOutputLines().Last().Trim();

            var expectedLastLine = $"Successfully created package '{packageFilePath}'.";

            if (expectedLastLine != lastLine)
            {
                throw new Exception($"dotnet automation error. Command:\n{ ProcessRunner.GetCommandLineIncantation(dotnetExecutableFilePath.Value, arguments) }\n\nOutput:\n{ outputCollector.GetOutputText()}\n\nError:\n{ outputCollector.GetErrorText()}\n");
            }

            logger.LogInformation($"{projectFilePath} - Packed project to:\n{packageFilePath}");

            return(packageFilePath);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Gets the version for a project file.
        /// If no version is present, returns <see cref="VersionHelper.None"/>.
        /// </summary>
        public static Version GetVersion(ProjectFilePath projectFilePath)
        {
            // Read the project file path in as XML.
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(projectFilePath.Value);

            // Determine if there is a Project/PropertyGroup/Version node.
            var versionNodeXPath = "//Project/PropertyGroup/Version";
            var versionNode      = xmlDoc.SelectSingleNode(versionNodeXPath);

            var hasVersion = versionNode != null;

            if (hasVersion)
            {
                var version = Version.Parse(versionNode.InnerText);
                return(version);
            }
            else
            {
                return(VersionHelper.None);
            }
        }
        /// <summary>
        /// Provides any project file paths referenced by the input project file, and any project file paths referenced by those project file paths, and so on recursively, until all project file paths are accumulated.
        /// </summary>
        public static ProjectFilePath[] GetProjectReferencedProjectFilePathsRecursive(ProjectFilePath projectFilePath, ILogger logger)
        {
            var uniqueProjects = new HashSet <ProjectFilePath>();
            var queue          = new Queue <ProjectFilePath>();

            queue.Enqueue(projectFilePath);
            // Do not include the initial project file path in the output list of referenced project file paths.

            while (queue.Count > 0)
            {
                var currentProjectFilePath = queue.Dequeue();

                logger.LogDebug($"Getting project-references for: {currentProjectFilePath}");

                var currentProjectReferencedProjects = DotnetCommandServicesProvider.GetProjectReferencedProjectFilePaths(currentProjectFilePath);
                foreach (var referencedProject in currentProjectReferencedProjects)
                {
                    if (!uniqueProjects.Contains(referencedProject))
                    {
                        uniqueProjects.Add(referencedProject);
                        queue.Enqueue(referencedProject);
                    }
                }
            }

            var projectFilePaths = new List <ProjectFilePath>(uniqueProjects);

            projectFilePaths.Sort();

            return(projectFilePaths.ToArray());
        }
Ejemplo n.º 27
0
 public override string ToString()
 {
     return(ProjectFilePath.GetFileNameWithoutExtension());
 }
 /// <summary>
 /// Uses the <see cref="DotnetNewConventions.Instance"/>.
 /// </summary>
 public static void CreateProjectFile(DotnetNewProjectType projectType, ProjectFilePath projectFilePath, ILogger logger)
 {
     DotnetCommandServicesProvider.CreateProjectFile(projectType, projectFilePath, DotnetNewConventions.Instance, logger);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Visualizer for the debugger
 /// </summary>
 public override string ToString()
 {
     return(ProjectFilePath.ToString());
 }
        public static ProjectFilePath[] GetProjectReferencedProjectFilePathsRecursive(ProjectFilePath projectFilePath)
        {
            var projectFilePaths = DotnetCommandServicesProvider.GetProjectReferencedProjectFilePathsRecursive(projectFilePath, DummyLogger.Instance);

            return(projectFilePaths);
        }