in src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs [595:650]
private void ProduceContentAsset(NuGetPackageObject package, JProperty sharedAsset, IReadOnlyDictionary<string, string> preprocessorValues, string preprocessedOutputDirectory)
{
string pathToFinalAsset = package.GetFullPathToFile(sharedAsset.Name);
if (sharedAsset.Value["ppOutputPath"] != null)
{
if (preprocessedOutputDirectory == null)
{
throw new ExceptionFromResource(nameof(Strings.PreprocessedDirectoryNotSet), nameof(ContentPreprocessorOutputDirectory));
}
// We need the preprocessed output, so let's run the preprocessor here
pathToFinalAsset = Path.Combine(preprocessedOutputDirectory, package.Id, package.Version, (string)sharedAsset.Value["ppOutputPath"]);
if (!File.Exists(pathToFinalAsset))
{
Directory.CreateDirectory(Path.GetDirectoryName(pathToFinalAsset));
using (var input = new StreamReader(package.GetFullPathToFile(sharedAsset.Name), detectEncodingFromByteOrderMarks: true))
using (var output = new StreamWriter(pathToFinalAsset, append: false, encoding: input.CurrentEncoding))
{
Preprocessor.Preprocess(input, output, preprocessorValues);
}
_fileWrites.Add(new TaskItem(pathToFinalAsset));
}
}
if ((bool)sharedAsset.Value["copyToOutput"])
{
string outputPath = (string)sharedAsset.Value["outputPath"] ?? (string)sharedAsset.Value["ppOutputPath"];
if (outputPath != null)
{
var item = CreateItem(package, pathToFinalAsset, targetPath: outputPath);
_copyLocalItems.Add(item);
}
}
string buildAction = (string)sharedAsset.Value["buildAction"];
if (!string.Equals(buildAction, "none", StringComparison.OrdinalIgnoreCase))
{
var item = CreateItem(package, pathToFinalAsset);
// We'll put additional metadata on the item so we can convert it back to the real item group in our targets
item.SetMetadata("NuGetItemType", buildAction);
// If this is XAML, the build targets expect Link metadata to construct the relative path
if (string.Equals(buildAction, "Page", StringComparison.OrdinalIgnoreCase))
{
item.SetMetadata("Link", Path.Combine("NuGet", package.Id, package.Version, Path.GetFileName(sharedAsset.Name)));
}
_contentItems.Add(item);
}
}