in src/Tasks/Microsoft.NET.Build.Tasks/ProduceContentAssets.cs [122:191]
protected override void ExecuteCore()
{
var preprocessorValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
// If a preprocessor directory isn't set, then we won't have a place to generate.
if (!string.IsNullOrEmpty(ContentPreprocessorOutputDirectory))
{
// Assemble the preprocessor values up-front
var duplicatedPreprocessorKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var preprocessorValueItem in ContentPreprocessorValues ?? Enumerable.Empty<ITaskItem>())
{
if (preprocessorValues.ContainsKey(preprocessorValueItem.ItemSpec))
{
duplicatedPreprocessorKeys.Add(preprocessorValueItem.ItemSpec);
}
preprocessorValues[preprocessorValueItem.ItemSpec] = preprocessorValueItem.GetMetadata("Value");
}
foreach (var duplicatedPreprocessorKey in duplicatedPreprocessorKeys)
{
Log.LogWarning(Strings.DuplicatePreprocessorToken, duplicatedPreprocessorKey, preprocessorValues[duplicatedPreprocessorKey]);
}
AssetPreprocessor.ConfigurePreprocessor(ContentPreprocessorOutputDirectory, preprocessorValues);
}
var contentFileDeps = ContentFileDependencies ?? Enumerable.Empty<ITaskItem>();
var contentFileGroups = contentFileDeps
.Where(f => !ProduceOnlyPreprocessorFiles || IsPreprocessorFile(f))
.GroupBy(t => t.GetMetadata(MetadataKeys.NuGetPackageId));
foreach (var grouping in contentFileGroups)
{
// Is there an asset with our exact language? If so, we use that. Otherwise we'll simply collect "any" assets.
string codeLanguageToSelect;
if (string.IsNullOrEmpty(ProjectLanguage))
{
codeLanguageToSelect = "any";
}
else
{
string projectLanguage = NuGetUtils.GetLockFileLanguageName(ProjectLanguage);
if (grouping.Any(t => t.GetMetadata(MetadataKeys.CodeLanguage) == projectLanguage))
{
codeLanguageToSelect = projectLanguage;
}
else
{
codeLanguageToSelect = "any";
}
}
foreach (var contentFile in grouping)
{
// Ignore magic _._ placeholder files. We couldn't ignore them during the project language
// selection, since you could imagine somebody might have a package that puts assets under
// "any" but then uses _._ to opt some languages out of it
if (NuGetUtils.IsPlaceholderFile(contentFile.ItemSpec))
{
continue;
}
if (contentFile.GetMetadata(MetadataKeys.CodeLanguage) == codeLanguageToSelect)
{
ProduceContentAsset(contentFile);
}
}
}
}