public MSBuildTaskResultItem(MSBuildTask p) { this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; uo = (XmlElement)doc.CreateNode(XmlNodeType.Element, "Output", MSBuildFile.NamespaceName); }
public MSBuildTaskParameter(MSBuildTask p) { string name = "NoAttributeNameGiven"; this.parent = p; XmlDocument doc = parent.UnderlyingObject.OwnerDocument; uo = (XmlAttribute)doc.CreateNode(XmlNodeType.Attribute, name, null /*MSBuildFile.NamespaceName*/); }
public void AppendTask(MSBuildTask task) { // insert on this level this.tasks.Add(task); // insert on underlaying level XmlNode tn = task.UnderlyingObject; uo.AppendChild(tn); }
public void InjectVersioning(string versionPropertyName) { /* * <Target Name="MyAssemblyVersion" Outputs="@(GeneratedVersion)"> * <MakeDir Directories="$(IntermediateOutputPath)" /> * <AssemblyInfo CodeLanguage="CS" * AssemblyCompany="MyCompanyName" * AssemblyCopyright="Copyright $(CompanyName), All rights reserved." * AssemblyVersion="12.34.56.78" * AssemblyFileVersion="3.3.3.3" * OutputFile="$(IntermediateOutputPath)file1.cs"> * <Output TaskParameter="OutputFile" ItemName="Compile" /> * </AssemblyInfo> * </Target> */ MSBuildTarget targ = this.UnderlyingObject.CreateTarget(); targ.Name = "MyAssemblyVersion"; { MSBuildTask task = targ.CreateTask(); task.Name = "MakeDir"; task.AddParameter("Directories", "$(IntermediateOutputPath)"); targ.AppendTask(task); } { MSBuildPropertyGroup group = targ.CreatePropertyGroup(); group.Condition = " '$(" + versionPropertyName + ")' == '' "; group.AddProperty(versionPropertyName, "1.0.0.0"); targ.AppendPropertyGroup(group); } { MSBuildTask task = targ.CreateTask(); task.Name = "AssemblyInfo"; task.AddParameter("CodeLanguage", "CS"); task.AddParameter("AssemblyVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyVersion task.AddParameter("AssemblyFileVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyFileVersion task.AddParameter("AssemblyInformationalVersion", "$(" + versionPropertyName + ")"); // System.Reflection.AssemblyInformationalVersion task.AddParameter("OutputFile", "$(IntermediateOutputPath)AssemblyVersion.Generated.cs"); { MSBuildTaskResultItem resultItem = task.CreateResultItem(); resultItem.TaskParameter = "OutputFile"; resultItem.ItemName = "Compile"; task.AppendResultItem(resultItem); } targ.AppendTask(task); } this.UnderlyingObject.EnsureTargetExists("BeforeBuild"); this.UnderlyingObject.InsertTarget(targ); this.UnderlyingObject.AddDependOnTarget("BeforeBuild", targ.Name); }
// http://stackoverflow.com/questions/30943342/how-to-use-internalsvisibleto-attribute-with-strongly-named-assembly public void InjectInternalsVisibleTo(string assemblyName, string assemblyPublicKey) { MSBuildTarget targ = this.UnderlyingObject.CreateTarget(); targ.Name = "MyInsertInternalsTo"; { MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'true' task.Name = "AssemblyInfo"; task.AddParameter("CodeLanguage", "CS"); task.Condition = "'$(SignAssembly)' == 'true'"; task.AddParameter("InternalsVisibleTo", assemblyName + ", PublicKey=" + assemblyPublicKey); task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); { MSBuildTaskResultItem resultItem = task.CreateResultItem(); resultItem.TaskParameter = "OutputFile"; resultItem.ItemName = "Compile"; task.AppendResultItem(resultItem); } targ.AppendTask(task); } { MSBuildTask task = targ.CreateTask(); // '$(SignAssembly)' == 'false' task.Name = "AssemblyInfo"; task.AddParameter("CodeLanguage", "CS"); task.Condition = "'$(SignAssembly)' != 'true'"; task.AddParameter("InternalsVisibleTo", assemblyName); task.AddParameter("OutputFile", "$(IntermediateOutputPath)" + assemblyName + ".IVT.Generated.cs"); { MSBuildTaskResultItem resultItem = task.CreateResultItem(); resultItem.TaskParameter = "OutputFile"; resultItem.ItemName = "Compile"; task.AppendResultItem(resultItem); } targ.AppendTask(task); } this.UnderlyingObject.EnsureTargetExists("BeforeBuild"); this.UnderlyingObject.InsertTarget(targ); this.UnderlyingObject.AddDependOnTarget("BeforeBuild", targ.Name); }
public MSBuildTask CreateTask() { MSBuildTask res = new MSBuildTask(this); return(res); }