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 11, 2022
1 parent ccca5aa commit d7e99f5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 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
40 changes: 20 additions & 20 deletions Sharpmake/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,27 @@ internal void Resolve(string sourceRootPath, Resolver resolver)

public XResourcesImgContainer XResourcesImg = new XResourcesImgContainer();

[Resolver.Resolvable]
public class CustomTargetElement
{
public string Name = "";
public string TargetParameters = "";
public string CustomTasks = "";

public CustomTargetElement()
{ }

public CustomTargetElement(string name, string targetParameters, string customTasks)
{
Name = name;
TargetParameters = targetParameters;
CustomTasks = customTasks;
}
}

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 +2179,7 @@ public static void InitAspNetProject(this CSharpProject aspNetProject)

aspNetProject.NoneExtensions.Add(".pubxml");

aspNetProject.CustomTargets.Add(new CSharpProject.CustomTargetElement()
aspNetProject.CustomTargets.Add(new Project.CustomTargetElement()
{
Name = "MvcBuildViews",
TargetParameters = @"AfterTargets=""AfterBuild"" Condition=""'$(MvcBuildViews)' == 'true'""",
Expand Down Expand Up @@ -2311,7 +2330,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 @@ -2336,24 +2354,6 @@ public class CSharpProject : Project
/// </summary>
public bool GenerateDocumentationFile = false;

[Resolver.Resolvable]
public class CustomTargetElement
{
public string Name;
public string TargetParameters;
public string CustomTasks;

public CustomTargetElement()
{ }

public CustomTargetElement(string name, string targetParameters, string customTasks)
{
Name = name;
TargetParameters = targetParameters;
CustomTasks = customTasks;
}
}

[Resolver.Resolvable]
public class UsingTask
{
Expand Down

0 comments on commit d7e99f5

Please sign in to comment.