Skip to content

Commit

Permalink
[Vcxproj] Promote Custom target elements to Project level so it can a…
Browse files Browse the repository at this point in the history
…lso 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)
  • Loading branch information
kudaba committed Feb 8, 2022
1 parent ccca5aa commit 67480ae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
9 changes: 9 additions & 0 deletions Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,15 @@ internal static class Filters
";
}
}

public static class TargetElement
{
public static string CustomTarget =
@" <Target Name=""[targetElement.Name]"" [targetElement.TargetParameters]>
[targetElement.CustomTasks]
</Target>
";
}
}
}
}
9 changes: 9 additions & 0 deletions Sharpmake.Generators/VisualStudio/Vcxproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,15 @@ private void GenerateImpl(GenerationContext context, IList<string> 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.
Expand Down
20 changes: 13 additions & 7 deletions Sharpmake/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Project.Configuration>
{
Expand Down Expand Up @@ -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<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();

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
Expand Down Expand Up @@ -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'""",
Expand Down Expand Up @@ -2311,7 +2320,6 @@ public class CSharpProject : Project
public List<ComReference> ComReferences = new List<ComReference>();
public List<ImportProject> PreImportProjects = new List<ImportProject>();
public List<ImportProject> ImportProjects = new List<ImportProject>();
public List<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();
public List<UsingTask> UsingTasks = new List<UsingTask>();

public bool? WcfAutoStart; // Wcf Auto-Start service when debugging
Expand All @@ -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()
{ }

Expand Down

0 comments on commit 67480ae

Please sign in to comment.