Skip to content

Commit 67480ae

Browse files
committed
[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)
1 parent ccca5aa commit 67480ae

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,15 @@ internal static class Filters
462462
";
463463
}
464464
}
465+
466+
public static class TargetElement
467+
{
468+
public static string CustomTarget =
469+
@" <Target Name=""[targetElement.Name]"" [targetElement.TargetParameters]>
470+
[targetElement.CustomTasks]
471+
</Target>
472+
";
473+
}
465474
}
466475
}
467476
}

Sharpmake.Generators/VisualStudio/Vcxproj.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,15 @@ private void GenerateImpl(GenerationContext context, IList<string> generatedFile
676676
}
677677
fileGenerator.Write(Template.Project.ProjectTargetsEnd);
678678

679+
foreach (var element in context.Project.CustomTargets)
680+
{
681+
using (fileGenerator.Declare("project", context.Project))
682+
using (fileGenerator.Declare("targetElement", element))
683+
{
684+
fileGenerator.Write(Template.TargetElement.CustomTarget);
685+
}
686+
}
687+
679688
// in case we are using fast build we do not want to write most dependencies
680689
// in the vcxproj because they are handled internally in the bff.
681690
// Nevertheless, non-fastbuild dependencies (such as C# projects) must be written.

Sharpmake/Project.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222

2323
namespace Sharpmake
2424
{
25+
[Resolver.Resolvable]
26+
public class CustomTargetElement
27+
{
28+
public string Name = "";
29+
public string TargetParameters = "";
30+
public string CustomTasks = "";
31+
}
32+
2533
[Resolver.Resolvable]
2634
public partial class Project : Configurable<Project.Configuration>
2735
{
@@ -225,6 +233,7 @@ internal void Resolve(string sourceRootPath, Resolver resolver)
225233

226234
public Strings CustomPropsFiles = new Strings(); // vs2010+ .props files
227235
public Strings CustomTargetsFiles = new Strings(); // vs2010+ .targets files
236+
public List<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();
228237

229238
public Strings LibraryPathsExcludeFromWarningRegex = new Strings(); // Library paths where we want to ignore the path doesn't exist warning
230239
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)
21602169

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

2163-
aspNetProject.CustomTargets.Add(new CSharpProject.CustomTargetElement()
2172+
aspNetProject.CustomTargets.Add(new CustomTargetElement()
21642173
{
21652174
Name = "MvcBuildViews",
21662175
TargetParameters = @"AfterTargets=""AfterBuild"" Condition=""'$(MvcBuildViews)' == 'true'""",
@@ -2311,7 +2320,6 @@ public class CSharpProject : Project
23112320
public List<ComReference> ComReferences = new List<ComReference>();
23122321
public List<ImportProject> PreImportProjects = new List<ImportProject>();
23132322
public List<ImportProject> ImportProjects = new List<ImportProject>();
2314-
public List<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();
23152323
public List<UsingTask> UsingTasks = new List<UsingTask>();
23162324

23172325
public bool? WcfAutoStart; // Wcf Auto-Start service when debugging
@@ -2337,12 +2345,10 @@ public class CSharpProject : Project
23372345
public bool GenerateDocumentationFile = false;
23382346

23392347
[Resolver.Resolvable]
2340-
public class CustomTargetElement
2341-
{
2342-
public string Name;
2343-
public string TargetParameters;
2344-
public string CustomTasks;
2348+
[Obsolete("Use Sharpmake.CustomTargetElement instead")]
23452349

2350+
public class CustomTargetElement : Sharpmake.CustomTargetElement
2351+
{
23462352
public CustomTargetElement()
23472353
{ }
23482354

0 commit comments

Comments
 (0)