Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix .NET 8 SDK Artifacts output layout #423

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions AvaloniaVS.Shared/Views/AvaloniaDesigner.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,26 @@ private async Task StartProcessAsync()
Log.Logger.Verbose("Finished AvaloniaDesigner.StartProcessAsync()");
}

private string GetIntermediateOutputPath(IVsBuildPropertyStorage storage)
{
// .NET 8 SDK Artifacts output layout
// https://learn.microsoft.com/en-us/dotnet/core/sdk/artifacts-output
// Example
// MSBuildProjectDirectory: X:\abcd\src\Mobius.Windows\
// IntermediateOutputPath: X:\abcd\src\artifacts\obj\Mobius.Windows\debug_net8.0-windows10.0.19041.0

var intermediateOutputPath = GetMSBuildProperty("IntermediateOutputPath", storage);
if (Path.IsPathRooted(intermediateOutputPath))
{
return Path.Combine(intermediateOutputPath, "Avalonia", "references");
}
else
{
var projDir = GetMSBuildProperty("MSBuildProjectDirectory", storage);
return Path.Combine(projDir, intermediateOutputPath.TrimStart(Path.DirectorySeparatorChar), "Avalonia", "references");
}
}

private void RebuildMetadata(string assemblyPath)
{
assemblyPath ??= SelectedTarget?.XamlAssembly;
Expand All @@ -531,8 +551,7 @@ private void RebuildMetadata(string assemblyPath)
() => new XamlBufferMetadata());
buffer.Properties["AssemblyName"] = Path.GetFileNameWithoutExtension(assemblyPath);
var storage = GetMSBuildPropertyStorage(SelectedTarget.Project);
string intermediateOutputPath = GetMSBuildProperty("MSBuildProjectDirectory", storage) + "\\"
+ GetMSBuildProperty("IntermediateOutputPath", storage) + "Avalonia\\references";
string intermediateOutputPath = GetIntermediateOutputPath(storage);
if (metadata.CompletionMetadata == null || metadata.NeedInvalidation)
{
CreateCompletionMetadataAsync(intermediateOutputPath, metadata).FireAndForget();
Expand All @@ -556,7 +575,7 @@ private static async Task CreateCompletionMetadataAsync(
dte.Events.BuildEvents.OnBuildBegin += (s, e) => _metadataCache.Clear();
}

Log.Logger.Verbose("Started AvaloniaDesigner.CreateCompletionMetadataAsync() for {ExecutablePath}", intermediateOutputPath);
Log.Logger.Information("Started AvaloniaDesigner.CreateCompletionMetadataAsync() for {ExecutablePath}", intermediateOutputPath);

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ public AvaloniaCompilationAssemblyProvider(string path)

public IEnumerable<string> GetAssemblies()
{
return File.ReadAllText(_path).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
try
{
return File.ReadAllText(_path).Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
}
catch (Exception ex) when
(ex is DirectoryNotFoundException || ex is FileNotFoundException)
{
return Array.Empty<string>();
}
catch (Exception ex)
{
throw new IOException($"Failed to read file '{_path}'.", ex);
}
}
}
}