From 67480ae73b655c5a29a39e47d6ebb28fcd3ba076 Mon Sep 17 00:00:00 2001 From: Chris Savoie Date: Thu, 21 Jun 2018 15:13:27 -0700 Subject: [PATCH] [Vcxproj] Promote Custom target elements to Project level so it can also be used in vcxproj. This was mainly needed to be able to suppress auto generation of AssemblyAttributes.cpp in clr projects: [More info](https://stackoverflow.com/questions/3104356/in-visual-studio-2010-why-is-the-netframework-version-v4-0-assemblyattributes-c) --- .../VisualStudio/Vcxproj.Template.cs | 9 +++++++++ Sharpmake.Generators/VisualStudio/Vcxproj.cs | 9 +++++++++ Sharpmake/Project.cs | 20 ++++++++++++------- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs index 601e2d0b7..64714afb0 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs @@ -462,6 +462,15 @@ internal static class Filters "; } } + + public static class TargetElement + { + public static string CustomTarget = +@" + [targetElement.CustomTasks] + +"; + } } } } diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs index 4c1cce30b..62d405bce 100644 --- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs +++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs @@ -676,6 +676,15 @@ private void GenerateImpl(GenerationContext context, IList generatedFile } fileGenerator.Write(Template.Project.ProjectTargetsEnd); + foreach (var element in context.Project.CustomTargets) + { + using (fileGenerator.Declare("project", context.Project)) + using (fileGenerator.Declare("targetElement", element)) + { + fileGenerator.Write(Template.TargetElement.CustomTarget); + } + } + // in case we are using fast build we do not want to write most dependencies // in the vcxproj because they are handled internally in the bff. // Nevertheless, non-fastbuild dependencies (such as C# projects) must be written. diff --git a/Sharpmake/Project.cs b/Sharpmake/Project.cs index a4ca9d2be..f2c6fa642 100644 --- a/Sharpmake/Project.cs +++ b/Sharpmake/Project.cs @@ -22,6 +22,14 @@ namespace Sharpmake { + [Resolver.Resolvable] + public class CustomTargetElement + { + public string Name = ""; + public string TargetParameters = ""; + public string CustomTasks = ""; + } + [Resolver.Resolvable] public partial class Project : Configurable { @@ -225,6 +233,7 @@ internal void Resolve(string sourceRootPath, Resolver resolver) public Strings CustomPropsFiles = new Strings(); // vs2010+ .props files public Strings CustomTargetsFiles = new Strings(); // vs2010+ .targets files + public List CustomTargets = new List(); public Strings LibraryPathsExcludeFromWarningRegex = new Strings(); // Library paths where we want to ignore the path doesn't exist warning public Strings IncludePathsExcludeFromWarningRegex = new Strings(); // Include paths where we want to ignore the path doesn't exist warning @@ -2160,7 +2169,7 @@ public static void InitAspNetProject(this CSharpProject aspNetProject) aspNetProject.NoneExtensions.Add(".pubxml"); - aspNetProject.CustomTargets.Add(new CSharpProject.CustomTargetElement() + aspNetProject.CustomTargets.Add(new CustomTargetElement() { Name = "MvcBuildViews", TargetParameters = @"AfterTargets=""AfterBuild"" Condition=""'$(MvcBuildViews)' == 'true'""", @@ -2311,7 +2320,6 @@ public class CSharpProject : Project public List ComReferences = new List(); public List PreImportProjects = new List(); public List ImportProjects = new List(); - public List CustomTargets = new List(); public List UsingTasks = new List(); public bool? WcfAutoStart; // Wcf Auto-Start service when debugging @@ -2337,12 +2345,10 @@ public class CSharpProject : Project public bool GenerateDocumentationFile = false; [Resolver.Resolvable] - public class CustomTargetElement - { - public string Name; - public string TargetParameters; - public string CustomTasks; + [Obsolete("Use Sharpmake.CustomTargetElement instead")] + public class CustomTargetElement : Sharpmake.CustomTargetElement + { public CustomTargetElement() { }