diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs
index b6e6e762c..622324a52 100644
--- a/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs
+++ b/Sharpmake.Generators/VisualStudio/Vcxproj.Template.cs
@@ -222,6 +222,14 @@ public static class Project
@"
";
+ public static string ProjectFilesHeaderBegin =
+ @"
+";
+
+ public static string ProjectFilesHeaderEnd =
+ @"
+";
+
public static string ProjectFilesNatvis =
@"
";
diff --git a/Sharpmake.Generators/VisualStudio/Vcxproj.cs b/Sharpmake.Generators/VisualStudio/Vcxproj.cs
index e1f8b54fd..b31d65cf2 100644
--- a/Sharpmake.Generators/VisualStudio/Vcxproj.cs
+++ b/Sharpmake.Generators/VisualStudio/Vcxproj.cs
@@ -1245,6 +1245,21 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera
var customSourceFiles = new Dictionary>();
foreach (ProjectFile projectFile in allFiles)
{
+ //First check if this projectFile is present in any of the configuration, if excluded from all, don't add it
+ bool addFile = false;
+ foreach (Project.Configuration conf in context.ProjectConfigurations)
+ {
+ if (conf.ResolvedSourceFilesExclude.Contains(projectFile.FileName) == false)
+ {
+ addFile = true;
+ break;
+ }
+ }
+ if (addFile == false)
+ {
+ continue;
+ }
+
string type = null;
if (context.Project.ExtensionBuildTools.TryGetValue(projectFile.FileExtension, out type))
{
@@ -1312,8 +1327,38 @@ private void GenerateFilesSection(IVcxprojGenerationContext context, IFileGenera
{
foreach (ProjectFile file in includeFiles)
{
+ bool writeEnd = false;
using (fileGenerator.Declare("file", file))
- fileGenerator.Write(Template.Project.ProjectFilesHeader);
+ {
+ foreach (Project.Configuration conf in context.ProjectConfigurations)
+ {
+ using (fileGenerator.Declare("conf", conf))
+ using (fileGenerator.Declare("platformName", Util.GetPlatformString(conf.Platform, conf.Project)))
+ {
+ bool isExcludeFromBuild = conf.ResolvedSourceFilesBuildExclude.Contains(file.FileName);
+ if (isExcludeFromBuild)
+ {
+ if (writeEnd == false)
+ {
+ fileGenerator.Write(Template.Project.ProjectFilesHeaderBegin);
+ writeEnd = true;
+ }
+ fileGenerator.Write(Template.Project.ProjectFilesSourceExcludeFromBuild);
+ }
+
+ }
+ }
+
+ if (writeEnd)
+ {
+ fileGenerator.Write(Template.Project.ProjectFilesHeaderEnd);
+ }
+ else
+ {
+ fileGenerator.Write(Template.Project.ProjectFilesHeader);
+ }
+ }
+
}
}
fileGenerator.Write(Template.Project.ProjectFilesEnd);
diff --git a/Sharpmake/Project.Configuration.cs b/Sharpmake/Project.Configuration.cs
index f7baa5f98..132d8b43a 100644
--- a/Sharpmake/Project.Configuration.cs
+++ b/Sharpmake/Project.Configuration.cs
@@ -303,6 +303,14 @@ public OutputType Output
public Strings SourceFilesFiltersRegex = new Strings();
+ ///
+ /// Excluded file from project for this configuration
+ ///
+ public Strings SourceFilesExclude = new Strings();
+
+ public Strings SourceFilesExcludeRegex = new Strings();
+
+
///
/// Sources file that match this regex will be compiled as C Files
///
@@ -1045,6 +1053,8 @@ public void GeneratorSetGeneratedInformation(string executableExtension, string
public Strings ResolvedSourceFilesBuildExclude = new Strings();
+ public Strings ResolvedSourceFilesExclude = new Strings();
+
public Strings ResolvedSourceFilesBlobExclude = new Strings();
public Strings ResolvedSourceFilesWithCompileAsCOption = new Strings();
diff --git a/Sharpmake/Project.cs b/Sharpmake/Project.cs
index f66a108fa..a0bfe8d9e 100644
--- a/Sharpmake/Project.cs
+++ b/Sharpmake/Project.cs
@@ -814,8 +814,23 @@ internal virtual void ResolveSourceFiles(Builder builder)
if (conf.IsFastBuild && conf.FastBuildBlobbed)
fastBuildBlobs = true;
+ var confSourceFilesExcludeRegex = RegexCache.GetCachedRegexes(conf.SourceFilesExcludeRegex);
+
+ // Remove file that match conf.SourceFilesExcludeRegex
+ if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, SourceFiles), SourceFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
+ System.Diagnostics.Debugger.Break();
+ if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, ResourceFiles), ResourceFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
+ System.Diagnostics.Debugger.Break();
+ if (AddMatchFiles(RootPath, Util.PathGetRelative(RootPath, NatvisFiles), NatvisFiles, ref conf.SourceFilesExclude, confSourceFilesExcludeRegex))
+ System.Diagnostics.Debugger.Break();
+
conf.ResolvedSourceFilesBuildExclude.AddRange(SourceFilesExclude);
+ //Add SourceFilesExclude also to ResolvedSourceFilesBuildExclude in case we end up needing file for
+ //another configuration that way it gets added but excluded from build in this config
+ conf.ResolvedSourceFilesBuildExclude.AddRange(conf.SourceFilesExclude);
+ conf.ResolvedSourceFilesExclude.AddRange(conf.SourceFilesExclude);
+
// add SourceFilesBuildExclude from the project
if (DebugBreaks.ShouldBreakOnSourcePath(DebugBreaks.Context.Resolving, ResolvedSourceFilesBuildExclude))
System.Diagnostics.Debugger.Break();
@@ -939,6 +954,7 @@ internal virtual void ResolveSourceFiles(Builder builder)
conf.ResolvedSourceFilesBuildExclude.Add(sourceFile);
}
Util.ResolvePath(SourceRootPath, ref conf.ResolvedSourceFilesBuildExclude);
+ Util.ResolvePath(SourceRootPath, ref conf.ResolvedSourceFilesExclude);
}
}
diff --git a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj
index 909975cdc..c47bb6b88 100644
--- a/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj
+++ b/samples/QTFileCustomBuild/reference/projects/qtfilecustombuild_vs2017_win64.vcxproj
@@ -373,9 +373,18 @@
-
-
-
+
+ true
+ true
+
+
+ true
+ true
+
+
+ true
+ true
+