Copy the "copy to output" files on compile
This commit is contained in:
parent
f1f1db0d8e
commit
25c35907b8
3 changed files with 67 additions and 70 deletions
|
@ -138,7 +138,7 @@ namespace Microsoft.Extensions.ProjectModel.Files
|
||||||
get { return SharedPatternsGroup.SearchFiles(_projectDirectory).Distinct(); }
|
get { return SharedPatternsGroup.SearchFiles(_projectDirectory).Distinct(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<string> GetFilesForBundling(IEnumerable<string> additionalExcludePatterns = null)
|
public IEnumerable<string> GetCopyToOutputFiles(IEnumerable<string> additionalExcludePatterns = null)
|
||||||
{
|
{
|
||||||
var patternGroup = new PatternGroup(ContentPatternsGroup.IncludePatterns,
|
var patternGroup = new PatternGroup(ContentPatternsGroup.IncludePatterns,
|
||||||
ContentPatternsGroup.ExcludePatterns.Concat(additionalExcludePatterns ?? new List<string>()),
|
ContentPatternsGroup.ExcludePatterns.Concat(additionalExcludePatterns ?? new List<string>()),
|
||||||
|
|
|
@ -10,7 +10,6 @@ using Microsoft.DotNet.Cli.Compiler.Common;
|
||||||
using Microsoft.DotNet.Tools.Common;
|
using Microsoft.DotNet.Tools.Common;
|
||||||
using Microsoft.Extensions.ProjectModel;
|
using Microsoft.Extensions.ProjectModel;
|
||||||
using Microsoft.Extensions.ProjectModel.Compilation;
|
using Microsoft.Extensions.ProjectModel.Compilation;
|
||||||
using Microsoft.Extensions.ProjectModel.Graph;
|
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Compiler
|
namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
@ -349,6 +348,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
private static void MakeRunnable(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
|
private static void MakeRunnable(ProjectContext runtimeContext, string outputPath, LibraryExporter exporter)
|
||||||
{
|
{
|
||||||
|
CopyContents(runtimeContext, outputPath);
|
||||||
|
|
||||||
if (runtimeContext.TargetFramework.IsDesktop())
|
if (runtimeContext.TargetFramework.IsDesktop())
|
||||||
{
|
{
|
||||||
// On desktop we need to copy dependencies since we don't own the host
|
// On desktop we need to copy dependencies since we don't own the host
|
||||||
|
@ -603,5 +604,69 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
File.Copy(file.ResolvedPath, Path.Combine(outputPath, Path.GetFileName(file.ResolvedPath)), overwrite: true);
|
File.Copy(file.ResolvedPath, Path.Combine(outputPath, Path.GetFileName(file.ResolvedPath)), overwrite: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void CopyContents(ProjectContext context, string outputPath)
|
||||||
|
{
|
||||||
|
var sourceFiles = context.ProjectFile.Files.GetCopyToOutputFiles();
|
||||||
|
Copy(sourceFiles, context.ProjectDirectory, outputPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Copy(IEnumerable<string> sourceFiles, string sourceDirectory, string targetDirectory)
|
||||||
|
{
|
||||||
|
if (sourceFiles == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(sourceFiles));
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceDirectory = EnsureTrailingSlash(sourceDirectory);
|
||||||
|
targetDirectory = EnsureTrailingSlash(targetDirectory);
|
||||||
|
|
||||||
|
foreach (var sourceFilePath in sourceFiles)
|
||||||
|
{
|
||||||
|
var fileName = Path.GetFileName(sourceFilePath);
|
||||||
|
|
||||||
|
var targetFilePath = sourceFilePath.Replace(sourceDirectory, targetDirectory);
|
||||||
|
var targetFileParentFolder = Path.GetDirectoryName(targetFilePath);
|
||||||
|
|
||||||
|
// Create directory before copying a file
|
||||||
|
if (!Directory.Exists(targetFileParentFolder))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(targetFileParentFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Copy(
|
||||||
|
sourceFilePath,
|
||||||
|
targetFilePath,
|
||||||
|
overwrite: true);
|
||||||
|
|
||||||
|
// clear read-only bit if set
|
||||||
|
var fileAttributes = File.GetAttributes(targetFilePath);
|
||||||
|
if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
||||||
|
{
|
||||||
|
File.SetAttributes(targetFilePath, fileAttributes & ~FileAttributes.ReadOnly);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string EnsureTrailingSlash(string path)
|
||||||
|
{
|
||||||
|
return EnsureTrailingCharacter(path, Path.DirectorySeparatorChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string EnsureTrailingCharacter(string path, char trailingCharacter)
|
||||||
|
{
|
||||||
|
if (path == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(path));
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the path is empty, we want to return the original string instead of a single trailing character.
|
||||||
|
if (path.Length == 0 || path[path.Length - 1] == trailingCharacter)
|
||||||
|
{
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path + trailingCharacter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,10 +128,6 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
// Use a library exporter to collect publish assets
|
// Use a library exporter to collect publish assets
|
||||||
var exporter = context.CreateExporter(configuration);
|
var exporter = context.CreateExporter(configuration);
|
||||||
|
|
||||||
// Copy things marked as copy to output (which we don't have yet)
|
|
||||||
// so does copy too many things
|
|
||||||
CopyContents(context, outputPath);
|
|
||||||
|
|
||||||
foreach (var export in exporter.GetAllExports())
|
foreach (var export in exporter.GetAllExports())
|
||||||
{
|
{
|
||||||
// Skip copying project references
|
// Skip copying project references
|
||||||
|
@ -174,70 +170,6 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CopyContents(ProjectContext context, string outputPath)
|
|
||||||
{
|
|
||||||
var sourceFiles = context.ProjectFile.Files.GetFilesForBundling();
|
|
||||||
Copy(sourceFiles, context.ProjectDirectory, outputPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Copy(IEnumerable<string> sourceFiles, string sourceDirectory, string targetDirectory)
|
|
||||||
{
|
|
||||||
if (sourceFiles == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(sourceFiles));
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceDirectory = EnsureTrailingSlash(sourceDirectory);
|
|
||||||
targetDirectory = EnsureTrailingSlash(targetDirectory);
|
|
||||||
|
|
||||||
foreach (var sourceFilePath in sourceFiles)
|
|
||||||
{
|
|
||||||
var fileName = Path.GetFileName(sourceFilePath);
|
|
||||||
|
|
||||||
var targetFilePath = sourceFilePath.Replace(sourceDirectory, targetDirectory);
|
|
||||||
var targetFileParentFolder = Path.GetDirectoryName(targetFilePath);
|
|
||||||
|
|
||||||
// Create directory before copying a file
|
|
||||||
if (!Directory.Exists(targetFileParentFolder))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(targetFileParentFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
File.Copy(
|
|
||||||
sourceFilePath,
|
|
||||||
targetFilePath,
|
|
||||||
overwrite: true);
|
|
||||||
|
|
||||||
// clear read-only bit if set
|
|
||||||
var fileAttributes = File.GetAttributes(targetFilePath);
|
|
||||||
if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
|
|
||||||
{
|
|
||||||
File.SetAttributes(targetFilePath, fileAttributes & ~FileAttributes.ReadOnly);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string EnsureTrailingSlash(string path)
|
|
||||||
{
|
|
||||||
return EnsureTrailingCharacter(path, Path.DirectorySeparatorChar);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string EnsureTrailingCharacter(string path, char trailingCharacter)
|
|
||||||
{
|
|
||||||
if (path == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(path));
|
|
||||||
}
|
|
||||||
|
|
||||||
// if the path is empty, we want to return the original string instead of a single trailing character.
|
|
||||||
if (path.Length == 0 || path[path.Length - 1] == trailingCharacter)
|
|
||||||
{
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return path + trailingCharacter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void PublishFiles(IEnumerable<LibraryAsset> files, string outputPath)
|
private static void PublishFiles(IEnumerable<LibraryAsset> files, string outputPath)
|
||||||
{
|
{
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
|
|
Loading…
Reference in a new issue