예제 #1
0
        /// <summary>
        /// Creates a ProjectTargetElement representing this instance.  Attaches it to the specified root element.
        /// </summary>
        /// <param name="rootElement">The root element to which the new element will belong.</param>
        /// <returns>The new element.</returns>
        internal ProjectTargetElement ToProjectTargetElement(ProjectRootElement rootElement)
        {
            ProjectTargetElement target = rootElement.CreateTargetElement(Name);

            rootElement.AppendChild(target);

            target.Condition        = Condition;
            target.DependsOnTargets = DependsOnTargets;
            target.Inputs           = Inputs;
            target.Outputs          = Outputs;
            target.Returns          = Returns;

            foreach (ProjectTaskInstance taskInstance in Tasks)
            {
                ProjectTaskElement taskElement = target.AddTask(taskInstance.Name);
                taskElement.Condition           = taskInstance.Condition;
                taskElement.ContinueOnError     = taskInstance.ContinueOnError;
                taskElement.MSBuildArchitecture = taskInstance.MSBuildArchitecture;
                taskElement.MSBuildRuntime      = taskInstance.MSBuildRuntime;

                foreach (KeyValuePair <string, string> taskParameterEntry in taskInstance.Parameters)
                {
                    taskElement.SetParameter(taskParameterEntry.Key, taskParameterEntry.Value);
                }

                foreach (ProjectTaskInstanceChild outputInstance in taskInstance.Outputs)
                {
                    if (outputInstance is ProjectTaskOutputItemInstance)
                    {
                        ProjectTaskOutputItemInstance outputItemInstance = outputInstance as ProjectTaskOutputItemInstance;
                        taskElement.AddOutputItem(outputItemInstance.TaskParameter, outputItemInstance.ItemType, outputItemInstance.Condition);
                    }
                    else if (outputInstance is ProjectTaskOutputPropertyInstance)
                    {
                        ProjectTaskOutputPropertyInstance outputPropertyInstance = outputInstance as ProjectTaskOutputPropertyInstance;
                        taskElement.AddOutputItem(outputPropertyInstance.TaskParameter, outputPropertyInstance.PropertyName, outputPropertyInstance.Condition);
                    }
                }
            }

            return(target);
        }
예제 #2
0
        /// <summary>
        /// Adds a task element to the current target.
        /// </summary>
        /// <param name="name">The name of the task.</param>
        /// <param name="condition">An optional condition to add to the task.</param>
        /// <param name="parameters">An optional <see cref="IDictionary{String,String}"/> that contains the parameters to pass to the task.</param>
        /// <param name="continueOnError">An optional value indicating if the build should continue in the case of an error.  The valid values are:
        /// <list type="Bullet">
        ///   <item>
        ///     <description><code>WarnAndContinue</code> or <code>true</code> - When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as warnings.</description>
        ///   </item>
        ///   <item>
        ///     <description><code>ErrorAndContinue</code> - When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as errors.</description>
        ///   </item>
        ///   <item>
        ///     <description><code>ErrorAndStop</code> or <code>false</code> - (Default) When a task fails, the remaining tasks in the Target element and the build aren't executed, and the entire Target element and the build is considered to have failed.</description>
        ///   </item>
        /// </list>
        /// </param>
        /// <param name="architecture">an optional architecture for the task.</param>
        /// <param name="runtime">An optional runtime for the task.</param>
        /// <param name="label">An optional label to add to the task.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator Task(string name, string condition = null, IDictionary <string, string> parameters = null, string continueOnError = null, string architecture = null, string runtime = null, string label = null)
        {
            _lastTask = LastTarget.AddTask(name);

            _lastTask.ContinueOnError     = continueOnError;
            _lastTask.Condition           = condition;
            _lastTask.Label               = label;
            _lastTask.MSBuildArchitecture = architecture;
            _lastTask.MSBuildRuntime      = runtime;

            if (parameters != null)
            {
                foreach (KeyValuePair <string, string> parameter in parameters.Where(i => i.Value != null))
                {
                    _lastTask.SetParameter(parameter.Key, parameter.Value);
                }
            }

            return(this);
        }
예제 #3
0
        public void ReadParameters()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'>
                            <t1 p1='v1' p2='v2' />
                        </Target>
                    </Project>
                ";

            ProjectTaskElement task = GetTaskFromContent(content);

            var parameters = Helpers.MakeDictionary(task.Parameters);

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual("v1", parameters["p1"]);
            Assert.AreEqual("v2", parameters["p2"]);

            Assert.AreEqual("v1", task.GetParameter("p1"));
            Assert.AreEqual(String.Empty, task.GetParameter("xxxx"));
        }
        public void BuildProject(string projectName, IEnumerable <ComponentGeneratorOutput> files, string csprojDir, string packageConfigFilename)
        {
            ProjectRootElement root = ProjectRootElement.Create();

            AddProperties(projectName, root);

            // references
            AddItems(root, "Reference", "System", "System.Core", "System.Drawing", "System.Xml.Linq", "System.Data.DataSetExtensions", "Microsoft.CSharp", "System.Data", "System.Net.Http", "System.Xml");
            // items to compile
            AddItems(root, "Compile", files.Select(file => file.CsFilePath).ToArray());

            AddItems(root, "None", packageConfigFilename);
            ProjectTargetElement target = root.AddTarget("Build");
            ProjectTaskElement   task   = target.AddTask("Csc");

            task.SetParameter("Sources", "@(Compile)");
            task.SetParameter("OutputAssembly", $"{projectName}.dll");
            AddImports(root);

            root.Save($"{csprojDir}\\{projectName}.csproj");
        }
예제 #5
0
        public void ReadParameters()
        {
            string content = @"
                    <Project>
                        <Target Name='t'>
                            <t1 p1='v1' p2='v2' />
                        </Target>
                    </Project>
                ";

            ProjectTaskElement task = GetTaskFromContent(content);

            var parameters = Helpers.MakeDictionary(task.Parameters);

            Assert.Equal(2, parameters.Count);
            Assert.Equal("v1", parameters["p1"]);
            Assert.Equal("v2", parameters["p2"]);

            Assert.Equal("v1", task.GetParameter("p1"));
            Assert.Equal(String.Empty, task.GetParameter("xxxx"));
        }
예제 #6
0
        /// <summary>
        /// Constructor called by Evaluator.
        /// All parameters are in the unevaluated state.
        /// Locations other than the main location may be null.
        /// </summary>
        internal ProjectTaskInstance
        (
            ProjectTaskElement element,
            IList <ProjectTaskInstanceChild> outputs
        )
        {
            ErrorUtilities.VerifyThrowInternalNull(element, "element");
            ErrorUtilities.VerifyThrowInternalNull(outputs, "outputs");

            // These are all immutable
            _name                        = element.Name;
            _condition                   = element.Condition;
            _continueOnError             = element.ContinueOnError;
            _msbuildArchitecture         = element.MSBuildArchitecture;
            _msbuildRuntime              = element.MSBuildRuntime;
            _location                    = element.Location;
            _conditionLocation           = element.ConditionLocation;
            _continueOnErrorLocation     = element.ContinueOnErrorLocation;
            _msbuildRuntimeLocation      = element.MSBuildRuntimeLocation;
            _msbuildArchitectureLocation = element.MSBuildArchitectureLocation;
            _parameters                  = element.ParametersForEvaluation;
            _outputs                     = new List <ProjectTaskInstanceChild>(outputs);
        }
예제 #7
0
        public void SetInvalidNullParameterName()
        {
            ProjectTaskElement task = GetBasicTask();

            task.SetParameter(null, "v1");
        }
예제 #8
0
        public void SetInvalidParameterNameCondition()
        {
            ProjectTaskElement task = GetBasicTask();

            task.SetParameter("Condition", "c");
        }
예제 #9
0
        public void SetInvalidParameterNameContinueOnError()
        {
            ProjectTaskElement task = GetBasicTask();

            task.SetParameter("ContinueOnError", "v");
        }
예제 #10
0
        public void SetInvalidNullParameterValue()
        {
            ProjectTaskElement task = GetBasicTask();

            task.SetParameter("p1", null);
        }
예제 #11
0
        public static void Verify(ProjectTaskElement viewXml, ProjectTaskElement realXml, ValidationContext context = null)
        {
            if (viewXml == null && realXml == null)
            {
                return;
            }
            VerifyProjectElement(viewXml, realXml, context);

            Assert.Equal(realXml.Name, viewXml.Name);

            Assert.Equal(realXml.ContinueOnError, viewXml.ContinueOnError);
            ViewValidation.VerifySameLocation(realXml.ContinueOnErrorLocation, viewXml.ContinueOnErrorLocation, context);
            Assert.Equal(realXml.MSBuildRuntime, viewXml.MSBuildRuntime);
            ViewValidation.VerifySameLocation(realXml.MSBuildRuntimeLocation, viewXml.MSBuildRuntimeLocation, context);

            Assert.Equal(realXml.MSBuildArchitecture, viewXml.MSBuildArchitecture);
            ViewValidation.VerifySameLocation(realXml.MSBuildArchitectureLocation, viewXml.MSBuildArchitectureLocation, context);

            ViewValidation.Verify(viewXml.Outputs, realXml.Outputs, ViewValidation.Verify, context);

            var realParams = realXml.Parameters;
            var viewParams = viewXml.Parameters;

            if (realParams == null)
            {
                Assert.Null(viewParams);
            }
            else
            {
                Assert.NotNull(viewParams);

                Assert.Equal(realParams.Count, viewParams.Count);
                foreach (var k in realParams.Keys)
                {
                    Assert.True(viewParams.ContainsKey(k));
                    Assert.Equal(realParams[k], viewParams[k]);
                }
            }

            var realParamsLoc = realXml.ParameterLocations;
            var viewParamsLoc = viewXml.ParameterLocations;

            if (realParamsLoc == null)
            {
                Assert.Null(viewParamsLoc);
            }
            else
            {
                Assert.NotNull(viewParamsLoc);

                var realPLocList = realParamsLoc.ToList();
                var viewPLocList = viewParamsLoc.ToList();

                Assert.Equal(realPLocList.Count, viewPLocList.Count);
                for (int li = 0; li < realPLocList.Count; li++)
                {
                    var rkvp = realPLocList[li];
                    var vkvp = viewPLocList[li];

                    Assert.Equal(rkvp.Key, vkvp.Key);
                    ViewValidation.VerifySameLocation(rkvp.Value, vkvp.Value, context);
                }
            }
        }
예제 #12
0
 private static void SetExecParameter(ProjectTaskElement execTask, string unevaluatedPropertyValue)
 => execTask.SetParameter(Command, unevaluatedPropertyValue);
예제 #13
0
        /// <summary>
        /// Configures the post-build event of the .NET Standard class library.
        /// </summary>
        public static void ConfigurePostBuildEvent(NewProjectSettings settings, bool verbose = false)
        {
            try
            {
                string csprojPath = Path.Combine(settings.SolutionPath, $"{settings.ProjectName}.ServiceLibrary", $"{settings.ProjectName}.ServiceLibrary.csproj");

                string executableWin;
                string executableMac;

                if (OperatingSystem.IsWindows())
                {
                    executableWin = Path.Combine(AppSettings.Default.AppPath, "flutnet.exe");
                    executableMac = $"{AppSettings.DefaultBinPath_macOS}/flutnet";
                }
                else
                {
                    executableWin = $"{AppSettings.DefaultBinPath_Windows}\\flutnet.exe";
                    executableMac = Path.Combine(AppSettings.Default.AppPath, "flutnet");
                }

                ProjectRootElement prjElement = ProjectRootElement.Open(csprojPath);

                // Configures the post-build event(s) for Visual Studio for Mac

                List <string> commandArguments = new List <string>
                {
                    executableMac.Quoted(), "pack",
                    "-a", "${TargetFile}".Quoted(),
                    "-n", settings.FlutterPackageName,
                    "-o", (settings.CreateFlutterSubfolder ? $"${{SolutionDir}}/{settings.FlutterSubfolderName}" : "${SolutionDir}").Quoted(),
                    "--force"
                };

                foreach (ProjectPropertyGroupElement groupElement in prjElement.PropertyGroups)
                {
                    if (groupElement.Condition.Contains("$(Configuration)") && groupElement.Condition.Contains("$(Platform)"))
                    {
                        ProjectPropertyElement propElement = groupElement.Properties.FirstOrDefault(p => p.Name == "CustomCommands");
                        propElement.Value = propElement.Value
                                            .Replace("<command></command>", $"<command>{string.Join(' ', commandArguments)}</command>");
                    }
                }

                // Configures the post-build event(s) for Visual Studio

                List <string> taskArguments = new List <string>
                {
                    executableWin.Quoted(), "pack",
                    "-a", "$(TargetPath)".Quoted(),
                    "-n", settings.FlutterPackageName,
                    "-o", (settings.CreateFlutterSubfolder ? $"$(SolutionDir)\\{settings.FlutterSubfolderName}" : "$(SolutionDir)").Quoted(),
                    "--force"
                };

                ProjectTargetElement targetElement = prjElement.Targets.FirstOrDefault(t => t.Name == "PostBuild");
                ProjectTaskElement   taskElement   = targetElement.AddTask("Exec");
                taskElement.SetParameter("Command", string.Join(' ', taskArguments));

                prjElement.Save();
            }
            catch (Exception e)
            {
                Log.Ex(e);
                throw new CommandLineException(CommandLineErrorCode.NewProject_CreateDotNetProjectsFailed, e);
            }
        }