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,
|
||||
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
|
||||
foreach (var sharedFile in project.Project.Files.SharedFiles)
|
||||
|
@ -169,17 +157,7 @@ namespace Microsoft.Extensions.ProjectModel.Compilation
|
|||
// No support for ref or native in projects, so runtimeAssemblies is just the same as compileAssemblies and nativeLibraries are empty
|
||||
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)
|
||||
{
|
||||
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()}");
|
||||
|
||||
//Set up Output Paths
|
||||
// Set up Output Paths
|
||||
string outputPath = GetOutputPath(context, configuration, outputOptionValue);
|
||||
string intermediateOutputPath = GetIntermediateOutputPath(context, configuration, outputOptionValue);
|
||||
|
||||
CleanOrCreateDirectory(outputPath);
|
||||
CleanOrCreateDirectory(intermediateOutputPath);
|
||||
Directory.CreateDirectory(outputPath);
|
||||
Directory.CreateDirectory(intermediateOutputPath);
|
||||
|
||||
// Create the library exporter
|
||||
var exporter = context.CreateExporter(configuration);
|
||||
|
@ -130,11 +130,11 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var projects = new Dictionary<string, ProjectDescription>();
|
||||
|
||||
// Build project references
|
||||
foreach (var dependency in dependencies.Where(d => d.CompilationAssemblies.Any()))
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
var projectDependency = dependency.Library as ProjectDescription;
|
||||
|
||||
if (projectDependency != null)
|
||||
if (projectDependency != null && projectDependency.Project.Files.SourceFiles.Any())
|
||||
{
|
||||
projects[projectDependency.Identity.Name] = projectDependency;
|
||||
}
|
||||
|
@ -143,7 +143,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
foreach (var projectDependency in Sort(projects))
|
||||
{
|
||||
// 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()
|
||||
.ForwardStdErr()
|
||||
.Execute();
|
||||
|
@ -163,13 +163,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
// ShowDependencyInfo(dependencies);
|
||||
|
||||
// Get compilation options
|
||||
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||
var outputExtension = ".dll";
|
||||
if (context.TargetFramework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault())
|
||||
{
|
||||
outputExtension = ".exe";
|
||||
}
|
||||
var outputName = Path.Combine(outputPath, context.ProjectFile.Name + outputExtension);
|
||||
var outputName = GetProjectOutput(context.ProjectFile, context.TargetFramework, configuration, outputPath);
|
||||
|
||||
// Assemble args
|
||||
var compilerArgs = new List<string>()
|
||||
|
@ -184,12 +178,26 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
compilerArgs.Add("-nowarn:CS1702");
|
||||
compilerArgs.Add("-nowarn:CS1705");
|
||||
|
||||
var compilationOptions = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
|
||||
// Add compilation options to the args
|
||||
ApplyCompilationOptions(compilationOptions, compilerArgs);
|
||||
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
compilerArgs.AddRange(dependency.CompilationAssemblies.Select(r => $"-r:\"{r.ResolvedPath}\""));
|
||||
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.SourceReferences.Select(s => $"\"{s}\""));
|
||||
}
|
||||
|
||||
|
@ -206,7 +214,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
compilerName = compilerName ?? "csc";
|
||||
|
||||
// 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);
|
||||
|
||||
var result = Command.Create($"dotnet-compile-{compilerName}", $"\"{rsp}\"")
|
||||
|
@ -256,7 +264,20 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
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)
|
||||
{
|
||||
var outputPath = string.Empty;
|
||||
|
@ -279,7 +300,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
private static string GetIntermediateOutputPath(ProjectContext context, string configuration, string outputOptionValue)
|
||||
{
|
||||
var intermediateOutputPath = String.Empty;
|
||||
var intermediateOutputPath = string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(outputOptionValue))
|
||||
{
|
||||
|
@ -299,7 +320,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
private static string GetDefaultRootOutputPath(ProjectContext context, string outputOptionValue)
|
||||
{
|
||||
string rootOutputPath = String.Empty;
|
||||
string rootOutputPath = string.Empty;
|
||||
|
||||
if (string.IsNullOrEmpty(outputOptionValue))
|
||||
{
|
||||
|
@ -355,16 +376,9 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var lines = new List<string>();
|
||||
foreach(var export in exporter.GetAllExports())
|
||||
{
|
||||
if (export.Library == runtimeContext.RootProject)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (export.Library is ProjectDescription)
|
||||
{
|
||||
// Copy project dependencies to the output folder
|
||||
CopyFiles(export.RuntimeAssemblies, outputPath);
|
||||
CopyFiles(export.NativeLibraries, outputPath);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -382,7 +396,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
private static void CopyHost(string target)
|
||||
{
|
||||
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)
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
}
|
||||
|
||||
// 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()
|
||||
.ForwardStdOut()
|
||||
.Execute();
|
||||
|
@ -134,6 +134,12 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
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()} ...");
|
||||
|
||||
PublishFiles(export.RuntimeAssemblies, outputPath);
|
||||
|
@ -155,7 +161,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
}
|
||||
|
||||
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());
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue