Skip to content

Commit d7e99f5

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 d7e99f5

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
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: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,27 @@ internal void Resolve(string sourceRootPath, Resolver resolver)
223223

224224
public XResourcesImgContainer XResourcesImg = new XResourcesImgContainer();
225225

226+
[Resolver.Resolvable]
227+
public class CustomTargetElement
228+
{
229+
public string Name = "";
230+
public string TargetParameters = "";
231+
public string CustomTasks = "";
232+
233+
public CustomTargetElement()
234+
{ }
235+
236+
public CustomTargetElement(string name, string targetParameters, string customTasks)
237+
{
238+
Name = name;
239+
TargetParameters = targetParameters;
240+
CustomTasks = customTasks;
241+
}
242+
}
243+
226244
public Strings CustomPropsFiles = new Strings(); // vs2010+ .props files
227245
public Strings CustomTargetsFiles = new Strings(); // vs2010+ .targets files
246+
public List<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();
228247

229248
public Strings LibraryPathsExcludeFromWarningRegex = new Strings(); // Library paths where we want to ignore the path doesn't exist warning
230249
public Strings IncludePathsExcludeFromWarningRegex = new Strings(); // Include paths where we want to ignore the path doesn't exist warning
@@ -2160,7 +2179,7 @@ public static void InitAspNetProject(this CSharpProject aspNetProject)
21602179

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

2163-
aspNetProject.CustomTargets.Add(new CSharpProject.CustomTargetElement()
2182+
aspNetProject.CustomTargets.Add(new Project.CustomTargetElement()
21642183
{
21652184
Name = "MvcBuildViews",
21662185
TargetParameters = @"AfterTargets=""AfterBuild"" Condition=""'$(MvcBuildViews)' == 'true'""",
@@ -2311,7 +2330,6 @@ public class CSharpProject : Project
23112330
public List<ComReference> ComReferences = new List<ComReference>();
23122331
public List<ImportProject> PreImportProjects = new List<ImportProject>();
23132332
public List<ImportProject> ImportProjects = new List<ImportProject>();
2314-
public List<CustomTargetElement> CustomTargets = new List<CustomTargetElement>();
23152333
public List<UsingTask> UsingTasks = new List<UsingTask>();
23162334

23172335
public bool? WcfAutoStart; // Wcf Auto-Start service when debugging
@@ -2336,24 +2354,6 @@ public class CSharpProject : Project
23362354
/// </summary>
23372355
public bool GenerateDocumentationFile = false;
23382356

2339-
[Resolver.Resolvable]
2340-
public class CustomTargetElement
2341-
{
2342-
public string Name;
2343-
public string TargetParameters;
2344-
public string CustomTasks;
2345-
2346-
public CustomTargetElement()
2347-
{ }
2348-
2349-
public CustomTargetElement(string name, string targetParameters, string customTasks)
2350-
{
2351-
Name = name;
2352-
TargetParameters = targetParameters;
2353-
CustomTasks = customTasks;
2354-
}
2355-
}
2356-
23572357
[Resolver.Resolvable]
23582358
public class UsingTask
23592359
{

0 commit comments

Comments
 (0)