Skip to content

Commit

Permalink
Always add .cs files generated by text templating (#324)
Browse files Browse the repository at this point in the history
* Add text templating generated files

Always include files generated by text templating (.tt), even if they don't exist yet.
These files are expected to be absent during a clean build, as they are generated
during the build process. Therefore, they cannot be left out of the csproj file.

* Remove unused import

* Removed unused parameter
  • Loading branch information
cmello authored Feb 9, 2024
1 parent c0937de commit 1a93118
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions Sharpmake.Generators/VisualStudio/Csproj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2288,30 +2288,18 @@ List<string> skipFiles
? "TextTemplatingFilePreprocessor"
: "TextTemplatingFileGenerator";

//Add the generated file if its in the remaining files.
bool generatedFileFound = remainingSourcesFiles.Concat(remainingResourcesFiles)
.Concat(remainingEmbeddedResourcesFiles)
.Concat(remainingNoneFiles).Contains(generatedFile);
AddContentGeneratedItem(itemGroups, ttFile, generatedFile, generator, false, _projectPathCapitalized, project, generatedFileFound);

// Always include files generated by text templating (.tt), even if they don't exist yet.
// These files are expected to be absent during a clean build, as they are generated
// during the build process. Therefore, they cannot be left out of the csproj file.
AddContentGeneratedItem(itemGroups, ttFile, generatedFile, generator, false, _projectPathCapitalized, project);

remainingNoneFiles.Remove(ttFile);
if (generatedFileFound)
{
//Remove generated file wherever it is.
remainingEmbeddedResourcesFiles.Remove(generatedFile);
remainingResourcesFiles.Remove(generatedFile);
remainingSourcesFiles.Remove(generatedFile);
remainingNoneFiles.Remove(generatedFile);
resolvedNoneFilesAddIfNewer.Remove(generatedFile);
}
else
{
_builder.LogWarningLine(
@"Warning: The generated file {0} for template file {1} is not found. Please generate and submit the file using Visual Studio.",
generatedFile,
ttFile);
}
//Remove generated file wherever it is.
remainingEmbeddedResourcesFiles.Remove(generatedFile);
remainingResourcesFiles.Remove(generatedFile);
remainingSourcesFiles.Remove(generatedFile);
remainingNoneFiles.Remove(generatedFile);
resolvedNoneFilesAddIfNewer.Remove(generatedFile);
}

//xaml files
Expand Down Expand Up @@ -2691,8 +2679,7 @@ private static void AddContentGeneratedItem(
string generator,
bool designTimeSharedInput,
string projectPath,
CSharpProject project,
bool addGeneratedFile)
CSharpProject project)
{
Trace.Assert(!string.IsNullOrEmpty(templateFile) && !string.IsNullOrEmpty(generatedFile));
itemGroups.Contents.Add(new ItemGroups.Content
Expand All @@ -2703,8 +2690,6 @@ private static void AddContentGeneratedItem(
LinkFolder = GetProjectLinkedFolder(templateFile, projectPath, project)
});

if (!addGeneratedFile)
return;
var generatedFileExtension = Path.GetExtension(generatedFile).ToLower();

//TODO Give some kind of additional TT directive to specify the build action directly?
Expand Down

0 comments on commit 1a93118

Please sign in to comment.