Skip to content

Commit bd88475

Browse files
authored
Add Content file deployment to internal storage (#858)
2 parents a783f54 + ba5f522 commit bd88475

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

vs-extension.shared/DeployProvider/DeployProvider.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public async Task DeployAsync(CancellationToken cancellationToken, TextWriter ou
9797
// this result is of type Microsoft.Build.Evaluation.Project
9898
var projectResult = await ((System.Threading.Tasks.Task<Microsoft.Build.Evaluation.Project>)buildProject.GetValue(Properties.ConfiguredProject));
9999

100+
// All the files that needs potentially to be deployed to the internal storage
101+
var contents = projectResult.Items.Where(m => m.ItemType == "Content" && m.Metadata.Any(t => t.Name == "CopyToOutputDirectory" && t.EvaluatedValue != "Never"));
102+
100103
if (!string.Equals(projectResult.Properties.First(p => p.Name == "OutputType").EvaluatedValue, "Exe", StringComparison.InvariantCultureIgnoreCase))
101104
{
102105
// This is not an executable project, it must be a referenced assembly
@@ -375,6 +378,47 @@ await Task.Run(async delegate
375378
// deployment successful
376379
await outputPaneWriter.WriteLineAsync("Deployment successful!");
377380

381+
// Now deploying to the internal storage if any
382+
if (contents.Any())
383+
{
384+
await outputPaneWriter.WriteLineAsync($"Deploying {contents.Count()} content files to internal storage");
385+
MessageCentre.InternalErrorWriteLine("Deploying content files to internal storage");
386+
foreach (var file in contents)
387+
{
388+
string fileName;
389+
var storPath = file.Metadata.Where(m => m.Name == "NF_StoragePath");
390+
if (storPath.Any())
391+
{
392+
fileName = storPath.FirstOrDefault().EvaluatedValue;
393+
}
394+
else
395+
{
396+
// Default is internal storage
397+
fileName = "I:\\" + file.EvaluatedInclude;
398+
}
399+
400+
await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deploying to {fileName}.");
401+
MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deploying to {fileName}.");
402+
403+
// Find the file where the exe is. There is an exe because otherwise, we won't be here with a simple DLL
404+
var fileAssemblyPath = projectResult.Properties.Where(m => m.Name == "TargetPath").First().EvaluatedValue;
405+
var contentFileName = Path.Combine(fileAssemblyPath.Substring(0, fileAssemblyPath.LastIndexOf(Path.DirectorySeparatorChar)), file.EvaluatedInclude);
406+
407+
// Deploying the file
408+
var ret = device.DebugEngine.AddStorageFile(fileName, File.ReadAllBytes(contentFileName));
409+
if (ret == Debugger.WireProtocol.StorageOperationErrorCode.NoError)
410+
{
411+
await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deplpoyed sucessfully.");
412+
MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deplpoyed sucessfully.");
413+
}
414+
else
415+
{
416+
await outputPaneWriter.WriteLineAsync($"{file.EvaluatedInclude} deployment error.");
417+
MessageCentre.InternalErrorWriteLine($"{file.EvaluatedInclude} deployment error.");
418+
}
419+
}
420+
}
421+
378422
// reset the hash for the connected device so the deployment information can be refreshed
379423
deviceExplorer.LastDeviceConnectedHash = 0;
380424
}

0 commit comments

Comments
 (0)