Change how paths to project references are resolved
- Removed project path resolution from ProjectModel - Flow output path to transitive dependencies - Don't copy project deps to output in publish or post compile
This commit is contained in:
parent
96dfcfa563
commit
b5ebe855ad
3 changed files with 50 additions and 52 deletions
|
@ -147,18 +147,6 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
||||||
assemblyPath,
|
assemblyPath,
|
||||||
Path.Combine(project.Project.ProjectDirectory, assemblyPath)));
|
Path.Combine(project.Project.ProjectDirectory, assemblyPath)));
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Add the project output to the metadata references, if there is source code
|
|
||||||
var outputPath = GetOutputPath(project);
|
|
||||||
if (project.Project.Files.SourceFiles.Any())
|
|
||||||
{
|
|
||||||
compileAssemblies.Add(new LibraryAsset(
|
|
||||||
project.Project.Name,
|
|
||||||
outputPath,
|
|
||||||
Path.Combine(project.Project.ProjectDirectory, outputPath)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add shared sources
|
// Add shared sources
|
||||||
foreach (var sharedFile in project.Project.Files.SharedFiles)
|
foreach (var sharedFile in project.Project.Files.SharedFiles)
|
||||||
|
@ -170,16 +158,6 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
||||||
return new LibraryExport(project, compileAssemblies, sourceReferences, compileAssemblies, Enumerable.Empty<LibraryAsset>());
|
return new LibraryExport(project, compileAssemblies, sourceReferences, compileAssemblies, Enumerable.Empty<LibraryAsset>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetOutputPath(ProjectDescription project)
|
|
||||||
{
|
|
||||||
var compilationOptions = project.Project.GetCompilerOptions(project.Framework, _configuration);
|
|
||||||
return Path.Combine(
|
|
||||||
"bin", // This can't access the Constant in Cli Utils. But the output path stuff is temporary right now anyway
|
|
||||||
_configuration,
|
|
||||||
project.Framework.GetTwoDigitShortFolderName(),
|
|
||||||
project.Project.Name + ".dll");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ResolvePath(Project project, string configuration, string path)
|
private static string ResolvePath(Project project, string configuration, string path)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(path))
|
if (string.IsNullOrEmpty(path))
|
||||||
|
|
|
@ -107,12 +107,12 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
{
|
{
|
||||||
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
Reporter.Output.WriteLine($"Compiling {context.RootProject.Identity.Name.Yellow()} for {context.TargetFramework.DotNetFrameworkName.Yellow()}");
|
||||||
|
|
||||||
//Set up Output Paths
|
// Set up Output Paths
|
||||||
string outputPath = GetOutputPath(context, configuration, outputOptionValue);
|
string outputPath = GetOutputPath(context, configuration, outputOptionValue);
|
||||||
string intermediateOutputPath = GetIntermediateOutputPath(context, configuration, outputOptionValue);
|
string intermediateOutputPath = GetIntermediateOutputPath(context, configuration, outputOptionValue);
|
||||||
|
|
||||||
CleanOrCreateDirectory(outputPath);
|
Directory.CreateDirectory(outputPath);
|
||||||
CleanOrCreateDirectory(intermediateOutputPath);
|
Directory.CreateDirectory(intermediateOutputPath);
|
||||||
|
|
||||||
// Create the library exporter
|
// Create the library exporter
|
||||||
var exporter = context.CreateExporter(configuration);
|
var exporter = context.CreateExporter(configuration);
|
||||||
|
@ -130,11 +130,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
var projects = new Dictionary<string, ProjectDescription>();
|
var projects = new Dictionary<string, ProjectDescription>();
|
||||||
|
|
||||||
// Build project references
|
// Build project references
|
||||||
foreach (var dependency in dependencies.Where(d => d.CompilationAssemblies.Any()))
|
foreach (var dependency in dependencies)
|
||||||
{
|
{
|
||||||
var projectDependency = dependency.Library as ProjectDescription;
|
var projectDependency = dependency.Library as ProjectDescription;
|
||||||
|
|
||||||
if (projectDependency != null)
|
if (projectDependency != null && projectDependency.Project.Files.SourceFiles.Any())
|
||||||
{
|
{
|
||||||
projects[projectDependency.Identity.Name] = projectDependency;
|
projects[projectDependency.Identity.Name] = projectDependency;
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
foreach (var projectDependency in Sort(projects))
|
foreach (var projectDependency in Sort(projects))
|
||||||
{
|
{
|
||||||
// Skip compiling project dependencies since we've already figured out the build order
|
// Skip compiling project dependencies since we've already figured out the build order
|
||||||
var compileResult = Command.Create("dotnet-compile", $"--framework {projectDependency.Framework} --configuration {configuration} --no-project-dependencies \"{projectDependency.Project.ProjectDirectory}\"")
|
var compileResult = Command.Create("dotnet-compile", $"--framework {projectDependency.Framework} --configuration {configuration} --output \"{outputPath}\" --no-project-dependencies \"{projectDependency.Project.ProjectDirectory}\"")
|
||||||
.ForwardStdOut()
|
.ForwardStdOut()
|
||||||
.ForwardStdErr()
|
.ForwardStdErr()
|
||||||
.Execute();
|
.Execute();
|
||||||
|
@ -163,13 +163,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
// ShowDependencyInfo(dependencies);
|
// ShowDependencyInfo(dependencies);
|
||||||
|
|
||||||
// Get compilation options
|
// Get compilation options
|
||||||
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
var outputName = GetProjectOutput(context.ProjectFile, context.TargetFramework, configuration, outputPath);
|
||||||
var outputExtension = ".dll";
|
|
||||||
if (context.TargetFramework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault())
|
|
||||||
{
|
|
||||||
outputExtension = ".exe";
|
|
||||||
}
|
|
||||||
var outputName = Path.Combine(outputPath, context.ProjectFile.Name + outputExtension);
|
|
||||||
|
|
||||||
// Assemble args
|
// Assemble args
|
||||||
var compilerArgs = new List<string>()
|
var compilerArgs = new List<string>()
|
||||||
|
@ -184,12 +178,26 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
compilerArgs.Add("-nowarn:CS1702");
|
compilerArgs.Add("-nowarn:CS1702");
|
||||||
compilerArgs.Add("-nowarn:CS1705");
|
compilerArgs.Add("-nowarn:CS1705");
|
||||||
|
|
||||||
|
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||||
// Add compilation options to the args
|
// Add compilation options to the args
|
||||||
ApplyCompilationOptions(compilationOptions, compilerArgs);
|
ApplyCompilationOptions(compilationOptions, compilerArgs);
|
||||||
|
|
||||||
foreach (var dependency in dependencies)
|
foreach (var dependency in dependencies)
|
||||||
|
{
|
||||||
|
var projectDependency = dependency.Library as ProjectDescription;
|
||||||
|
|
||||||
|
if (projectDependency != null)
|
||||||
|
{
|
||||||
|
if (projectDependency.Project.Files.SourceFiles.Any())
|
||||||
|
{
|
||||||
|
var projectOutputPath = GetProjectOutput(projectDependency.Project, projectDependency.Framework, configuration, outputPath);
|
||||||
|
compilerArgs.Add($"-r:\"{projectOutputPath}\"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
compilerArgs.AddRange(dependency.CompilationAssemblies.Select(r => $"-r:\"{r.ResolvedPath}\""));
|
compilerArgs.AddRange(dependency.CompilationAssemblies.Select(r => $"-r:\"{r.ResolvedPath}\""));
|
||||||
|
}
|
||||||
compilerArgs.AddRange(dependency.SourceReferences.Select(s => $"\"{s}\""));
|
compilerArgs.AddRange(dependency.SourceReferences.Select(s => $"\"{s}\""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +214,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
compilerName = compilerName ?? "csc";
|
compilerName = compilerName ?? "csc";
|
||||||
|
|
||||||
// Write RSP file
|
// Write RSP file
|
||||||
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-compile.{compilerName}.rsp");
|
var rsp = Path.Combine(intermediateOutputPath, $"dotnet-compile.{compilerName}.{context.ProjectFile.Name}.rsp");
|
||||||
File.WriteAllLines(rsp, compilerArgs);
|
File.WriteAllLines(rsp, compilerArgs);
|
||||||
|
|
||||||
var result = Command.Create($"dotnet-compile-{compilerName}", $"\"{rsp}\"")
|
var result = Command.Create($"dotnet-compile-{compilerName}", $"\"{rsp}\"")
|
||||||
|
@ -257,6 +265,19 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetProjectOutput(Project project, NuGetFramework framework, string configuration, string outputPath)
|
||||||
|
{
|
||||||
|
var compilationOptions = project.GetCompilerOptions(framework, configuration);
|
||||||
|
var outputExtension = ".dll";
|
||||||
|
|
||||||
|
if (framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault())
|
||||||
|
{
|
||||||
|
outputExtension = ".exe";
|
||||||
|
}
|
||||||
|
|
||||||
|
return Path.Combine(outputPath, project.Name + outputExtension);
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
private static string GetOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
||||||
{
|
{
|
||||||
var outputPath = string.Empty;
|
var outputPath = string.Empty;
|
||||||
|
@ -279,7 +300,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
private static string GetIntermediateOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
private static string GetIntermediateOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
||||||
{
|
{
|
||||||
var intermediateOutputPath = String.Empty;
|
var intermediateOutputPath = string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(outputOptionValue))
|
if (string.IsNullOrEmpty(outputOptionValue))
|
||||||
{
|
{
|
||||||
|
@ -299,7 +320,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
|
|
||||||
private static string GetDefaultRootOutputPath(ProjectContext context, string outputOptionValue)
|
private static string GetDefaultRootOutputPath(ProjectContext context, string outputOptionValue)
|
||||||
{
|
{
|
||||||
string rootOutputPath = String.Empty;
|
string rootOutputPath = string.Empty;
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(outputOptionValue))
|
if (string.IsNullOrEmpty(outputOptionValue))
|
||||||
{
|
{
|
||||||
|
@ -355,16 +376,9 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
var lines = new List<string>();
|
var lines = new List<string>();
|
||||||
foreach(var export in exporter.GetAllExports())
|
foreach(var export in exporter.GetAllExports())
|
||||||
{
|
{
|
||||||
if (export.Library == runtimeContext.RootProject)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (export.Library is ProjectDescription)
|
if (export.Library is ProjectDescription)
|
||||||
{
|
{
|
||||||
// Copy project dependencies to the output folder
|
continue;
|
||||||
CopyFiles(export.RuntimeAssemblies, outputPath);
|
|
||||||
CopyFiles(export.NativeLibraries, outputPath);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -382,7 +396,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
private static void CopyHost(string target)
|
private static void CopyHost(string target)
|
||||||
{
|
{
|
||||||
var hostPath = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
var hostPath = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
||||||
File.Copy(hostPath, target);
|
File.Copy(hostPath, target, overwrite: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<string> GenerateLines(LibraryExport export, IEnumerable<LibraryAsset> items, string type)
|
private static IEnumerable<string> GenerateLines(LibraryExport export, IEnumerable<LibraryAsset> items, string type)
|
||||||
|
|
|
@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile the project (and transitively, all it's dependencies)
|
// Compile the project (and transitively, all it's dependencies)
|
||||||
var result = Command.Create("dotnet-compile", $"--framework \"{context.TargetFramework.DotNetFrameworkName}\" --configuration \"{configuration}\" \"{context.ProjectFile.ProjectDirectory}\"")
|
var result = Command.Create("dotnet-compile", $"--framework \"{context.TargetFramework.DotNetFrameworkName}\" --output \"{outputPath}\" --configuration \"{configuration}\" \"{context.ProjectFile.ProjectDirectory}\"")
|
||||||
.ForwardStdErr()
|
.ForwardStdErr()
|
||||||
.ForwardStdOut()
|
.ForwardStdOut()
|
||||||
.Execute();
|
.Execute();
|
||||||
|
@ -134,6 +134,12 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
|
|
||||||
foreach (var export in exporter.GetAllExports())
|
foreach (var export in exporter.GetAllExports())
|
||||||
{
|
{
|
||||||
|
// Skip copying project references
|
||||||
|
if (export.Library is ProjectDescription)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
Reporter.Output.WriteLine($"Publishing {export.Library.Identity.ToString().Green().Bold()} ...");
|
||||||
|
|
||||||
PublishFiles(export.RuntimeAssemblies, outputPath);
|
PublishFiles(export.RuntimeAssemblies, outputPath);
|
||||||
|
@ -155,7 +161,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
||||||
}
|
}
|
||||||
|
|
||||||
var hostPath = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
var hostPath = Path.Combine(AppContext.BaseDirectory, Constants.HostExecutableName);
|
||||||
if(!File.Exists(hostPath))
|
if (!File.Exists(hostPath))
|
||||||
{
|
{
|
||||||
Reporter.Error.WriteLine($"Cannot find {Constants.HostExecutableName} in the dotnet directory.".Red());
|
Reporter.Error.WriteLine($"Cannot find {Constants.HostExecutableName} in the dotnet directory.".Red());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue