From 4beb6d93a446934359d75e6506f5aca8c51c8d43 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Tue, 3 Dec 2024 13:56:40 +0100 Subject: [PATCH] adding file deployment --- .../DeployProvider/DeployProvider.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/vs-extension.shared/DeployProvider/DeployProvider.cs b/vs-extension.shared/DeployProvider/DeployProvider.cs index 789ade2b..663b1c85 100644 --- a/vs-extension.shared/DeployProvider/DeployProvider.cs +++ b/vs-extension.shared/DeployProvider/DeployProvider.cs @@ -97,6 +97,9 @@ public async Task DeployAsync(CancellationToken cancellationToken, TextWriter ou // this result is of type Microsoft.Build.Evaluation.Project var projectResult = await ((System.Threading.Tasks.Task)buildProject.GetValue(Properties.ConfiguredProject)); + // All the files that needs potentially to be deployed to the internal storage + var contents = projectResult.Items.Where(m => m.ItemType == "Content" && m.Metadata.Any(t => t.Name == "CopyToOutputDirectory" && t.EvaluatedValue != "Never")); + if (!string.Equals(projectResult.Properties.First(p => p.Name == "OutputType").EvaluatedValue, "Exe", StringComparison.InvariantCultureIgnoreCase)) { // This is not an executable project, it must be a referenced assembly @@ -375,6 +378,47 @@ await Task.Run(async delegate // deployment successful await outputPaneWriter.WriteLineAsync("Deployment successful!"); + // Now deploying to the internal storage if any + if (contents.Any()) + { + await outputPaneWriter.WriteLineAsync($"Deploying {contents.Count()} content files to internal storage"); + MessageCentre.InternalErrorWriteLine("Deploying content files to internal storage"); + foreach (var file in contents) + { + string fileName; + var storPath = file.Metadata.Where(m => m.Name == "NF_StoragePath"); + if (storPath.Any()) + { + fileName = storPath.FirstOrDefault().EvaluatedValue; + } + else + { + // Default is internal storage + fileName = "I:\\" + file.EvaluatedInclude; + } + + await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deploying to {fileName}."); + MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deploying to {fileName}."); + + // Find the file where the exe is. There is an exe because otherwise, we won't be here with a simple DLL + var fileAssemblyPath = projectResult.Properties.Where(m => m.Name == "TargetPath").First().EvaluatedValue; + var contentFileName = Path.Combine(fileAssemblyPath.Substring(0, fileAssemblyPath.LastIndexOf(Path.DirectorySeparatorChar)), file.EvaluatedInclude); + + // Deploying the file + var ret = device.DebugEngine.AddStorageFile(fileName, File.ReadAllBytes(contentFileName)); + if (ret == Debugger.WireProtocol.StorageOperationErrorCode.NoError) + { + await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deplpoyed sucessfully."); + MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deplpoyed sucessfully."); + } + else + { + await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deployment error."); + MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deployment error."); + } + } + } + // reset the hash for the connected device so the deployment information can be refreshed deviceExplorer.LastDeviceConnectedHash = 0; }