private void CreateBuildFile(string extension, string folderName, Action <ProjectCreator>?creator, NewProjectFileOptions projectFileOptions)
        {
            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new ArgumentNullException(extension);
            }

            if (string.IsNullOrWhiteSpace(folderName))
            {
                throw new ArgumentNullException(folderName);
            }

            ProjectCreator project = ProjectCreator.Create(projectFileOptions: projectFileOptions);

            creator?.Invoke(project);

            FileText(Path.Combine(folderName, $"{LastPackage.Id}{extension}"), project.Xml);
        }
 /// <summary>
 /// Adds a &lt;ProjectReference /&gt; item to the current item group.
 /// </summary>
 /// <param name="projectCreator">A <see cref="ProjectCreator"/> to get the full path from.</param>
 /// <param name="name">An optional name for the project reference.</param>
 /// <param name="projectGuid">An optional project GUID for the project reference.</param>
 /// <param name="referenceOutputAssembly">An optional value indicating if the output of the project reference should be referenced by the current project.</param>
 /// <param name="metadata">An optional <see cref="IDictionary{String,String}"/> containing metadata for the item.</param>
 /// <param name="condition">An optional condition to add to the item.</param>
 /// <param name="label">An optional label to add to the item.</param>
 /// <returns>The current <see cref="ProjectCreator"/>.</returns>
 public ProjectCreator ItemProjectReference(ProjectCreator projectCreator, string name = null, string projectGuid = null, bool?referenceOutputAssembly = null, IDictionary <string, string> metadata = null, string condition = null, string label = null)
 {
     return(ItemProjectReference(projectCreator.RootElement, name, projectGuid, referenceOutputAssembly, metadata, condition, label));
 }
Пример #3
0
        /// <summary>
        /// Creates a legacy C# project.
        /// </summary>
        /// <param name="path">An optional relative or full path for the project.</param>
        /// <param name="outputType">An optional output type for the project.</param>
        /// <param name="targetFrameworkVersion">An optional target framework version for the project.</param>
        /// <param name="rootNamespace">An optional root namespace for the project.</param>
        /// <param name="assemblyName">An optional assembly name for the project.</param>
        /// <param name="defaultConfiguration">An optional default value for the Configuration property.</param>
        /// <param name="defaultPlatform">An optional default value for the Platform property.</param>
        /// <param name="projectGuid">An optional GUID for the project.  If none is specified, one is generated.</param>
        /// <param name="fileAlignment">An optional file alignment for the project.</param>
        /// <param name="projectCreator">An optional <see cref="Action{ProjectCreator}" /> delegate to call in the body of the project.</param>
        /// <param name="defaultTargets">An optional list of default targets for the project.</param>
        /// <param name="initialTargets">An optional list of initial targets for the project.</param>
        /// <param name="toolsVersion">An optional tools version for the project.</param>
        /// <param name="treatAsLocalProperty">An optional list of properties to treat as local properties.</param>
        /// <param name="projectCollection">An optional <see cref="ProjectCollection" /> to use when loading the project.</param>
        /// <param name="projectFileOptions">An optional <see cref="NewProjectFileOptions" /> specifying options when creating a new file.</param>
        /// <param name="globalProperties">An optional <see cref="IDictionary{String,String}" /> containing global properties for the project.</param>
        /// <returns>A <see cref="ProjectCreator" /> object that is used to construct an MSBuild project.</returns>
        public ProjectCreator LegacyCsproj(
            string?path                                   = null,
            string outputType                             = "Library",
            string targetFrameworkVersion                 = "v4.6",
            string rootNamespace                          = "ClassLibrary",
            string assemblyName                           = "ClassLibrary",
            string defaultConfiguration                   = "Debug",
            string defaultPlatform                        = "AnyCPU",
            string?projectGuid                            = null,
            string fileAlignment                          = "512",
            Action <ProjectCreator>?projectCreator        = null,
            string defaultTargets                         = "Build",
            string?initialTargets                         = null,
            string?toolsVersion                           = null,
            string?treatAsLocalProperty                   = null,
            ProjectCollection?projectCollection           = null,
            NewProjectFileOptions?projectFileOptions      = NewProjectFileOptions.IncludeAllOptions,
            IDictionary <string, string>?globalProperties = null)
        {
            if (path != null)
            {
                rootNamespace = assemblyName = Path.GetFileNameWithoutExtension(path);
            }

            return(ProjectCreator.Create(
                       path: path,
                       defaultTargets: defaultTargets,
                       initialTargets: initialTargets,
                       sdk: null,
                       toolsVersion: toolsVersion,
                       treatAsLocalProperty: treatAsLocalProperty,
                       projectCollection: projectCollection,
                       projectFileOptions: projectFileOptions,
                       globalProperties: globalProperties)
                   .Import(@"$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props", conditionOnExistence: true)
                   .PropertyGroup()
                   .Property("Configuration", defaultConfiguration, setIfEmpty: true)
                   .Property("Platform", defaultPlatform, setIfEmpty: true)
                   .Property("ProjectGuid", projectGuid ?? Guid.NewGuid().ToString("B").ToUpperInvariant())
                   .Property("OutputType", outputType)
                   .Property("RootNamespace", rootNamespace)
                   .Property("AssemblyName", assemblyName)
                   .Property("TargetFrameworkVersion", targetFrameworkVersion)
                   .Property("FileAlignment", fileAlignment)
                   .PropertyGroup(" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ")
                   .Property("DebugSymbols", "true")
                   .Property("DebugType", "full")
                   .Property("Optimize", "false")
                   .Property("OutputPath", @"bin\Debug")
                   .Property("DefineConstants", "DEBUG;TRACE")
                   .Property("ErrorReport", "prompt")
                   .Property("WarningLevel", "4")
                   .PropertyGroup(" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ")
                   .Property("DebugType", "pdbonly")
                   .Property("Optimize", "true")
                   .Property("OutputPath", @"bin\Release")
                   .Property("DefineConstants", "TRACE")
                   .Property("ErrorReport", "prompt")
                   .Property("WarningLevel", "4")
                   .ItemGroup()
                   .ItemReference("System")
                   .ItemReference("System.Core")
                   .ItemReference("System.Xml.Linq")
                   .ItemReference("System.Data.DataSetExtensions")
                   .ItemReference("Microsoft.CSharp")
                   .ItemReference("System.Data")
                   .ItemReference("System.Net.Http")
                   .ItemReference("System.Xml")
                   .CustomAction(projectCreator)
                   .Import(@"$(MSBuildToolsPath)\Microsoft.CSharp.targets"));
        }
Пример #4
0
 /// <summary>
 /// Adds an &lt;Import /&gt; element to the current project.
 /// </summary>
 /// <param name="projectCreator">A <see cref="ProjectCreator" /> to import.</param>
 /// <param name="condition">An optional condition to add to the import.</param>
 /// <param name="conditionOnExistence">An optional value indicating if a condition should be automatically added that checks if the specified project exists.</param>
 /// <param name="label">An optional label to add to the import.</param>
 /// <returns>The current <see cref="ProjectCreator" />.</returns>
 public ProjectCreator Import(ProjectCreator projectCreator, string?condition = null, bool conditionOnExistence = false, string?label = null)
 {
     return(Import(projectCreator.FullPath, condition, null, null, conditionOnExistence, label: label));
 }
        /// <summary>
        /// Adds a .targets file to the buildMultitargeting directory.
        /// </summary>
        /// <param name="creator">An <see cref="Action{ProjectCreator}" /> to generate the .targets file.</param>
        /// <param name="project">Receives the <see cref="ProjectCreator" /> of the created project file.</param>
        /// <param name="projectFileOptions">Optional <see cref="NewProjectFileOptions" /> for the .targets file.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
        public PackageRepository BuildMultiTargetingTargets(Action <ProjectCreator> creator, out ProjectCreator project, NewProjectFileOptions projectFileOptions = NewProjectFileOptions.IncludeAllOptions)
        {
            CreateBuildFile(".targets", "buildMultiTargeting", creator, projectFileOptions, out project);

            return(this);
        }
 /// <summary>
 /// Adds a .targets file to the buildMultitargeting directory.
 /// </summary>
 /// <param name="project">Receives the <see cref="ProjectCreator" /> of the created project file.</param>
 /// <param name="projectFileOptions">Optional <see cref="NewProjectFileOptions" /> for the .targets file.</param>
 /// <returns>The current <see cref="PackageRepository" />.</returns>
 public PackageRepository BuildMultiTargetingTargets(out ProjectCreator project, NewProjectFileOptions projectFileOptions = NewProjectFileOptions.IncludeAllOptions)
 {
     return(BuildMultiTargetingTargets(null, out project, projectFileOptions));
 }
        private void CreateBuildFile(string extension, string folderName, Action <ProjectCreator> creator, NewProjectFileOptions projectFileOptions, out ProjectCreator project)
        {
            if (_packageManifest == null)
            {
                throw new InvalidOperationException(Strings.ErrorWhenAddingBuildLogicRequiresPackage);
            }

            if (string.IsNullOrWhiteSpace(extension))
            {
                throw new ArgumentNullException(extension);
            }

            if (string.IsNullOrWhiteSpace(folderName))
            {
                throw new ArgumentNullException(folderName);
            }

            project = ProjectCreator.Create(
                path: Path.Combine(_packageManifest.Directory, folderName, $"{_packageManifest.Metadata.Id}{extension}"),
                projectFileOptions: projectFileOptions);

            creator?.Invoke(project);

            project.Save();
        }
        /// <summary>
        /// Adds a .props file to the buildTransitive directory.
        /// </summary>
        /// <param name="creator">An <see cref="Action{ProjectCreator}" /> to generate the .props file.</param>
        /// <param name="project">Receives the <see cref="ProjectCreator" /> of the created project file.</param>
        /// <param name="projectFileOptions">Optional <see cref="NewProjectFileOptions" /> for the .props file.</param>
        /// <returns>The current <see cref="PackageRepository" />.</returns>
        public PackageRepository BuildTransitiveProps(Action <ProjectCreator> creator, out ProjectCreator project, NewProjectFileOptions projectFileOptions = NewProjectFileOptions.IncludeAllOptions)
        {
            CreateBuildFile(".props", "buildTransitive", creator, projectFileOptions, out project);

            return(this);
        }
 /// <summary>
 /// Adds a .props file to the buildTransitive directory.
 /// </summary>
 /// <param name="project">Receives the <see cref="ProjectCreator" /> of the created project file.</param>
 /// <param name="projectFileOptions">Optional <see cref="NewProjectFileOptions" /> for the .props file.</param>
 /// <returns>The current <see cref="PackageRepository" />.</returns>
 public PackageRepository BuildTransitiveProps(out ProjectCreator project, NewProjectFileOptions projectFileOptions = NewProjectFileOptions.IncludeAllOptions)
 {
     return(BuildTransitiveProps(null, out project, projectFileOptions));
 }