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

Add Content file deployment to internal storage #814

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions VisualStudio.Extension-2019/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2419,6 +2419,24 @@
"VSSDK.IDE.12": "[12.0.4, 13.0.0)"
}
},
"csharp.assemblyinfotemplate": {
"type": "Project"
},
"csharp.blankapplication-vs2019": {
"type": "Project"
},
"csharp.classlibrary-vs2019": {
"type": "Project"
},
"csharp.classtemplate": {
"type": "Project"
},
"csharp.resourcetemplate": {
"type": "Project"
},
"csharp.testapplication-vs2019": {
"type": "Project"
},
"nanoFramework.Tools.BuildTasks": {
"type": "Project",
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ImageManifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/ImageManifestSchema/2014">
<Symbols>
<String Name="Resources" Value="/nanoFramework.Tools.VS2022.Extension;v2022.3.0.66;C78BE3280FBDE583;Component/Resources" />
<String Name="Resources" Value="/nanoFramework.Tools.VS2022.Extension;v2022.3.0.77;C78BE3280FBDE583;Component/Resources" />
<Guid Name="NanoFrameworkCatalog" Value="{23cf437f-5e0e-4b0c-8aa4-ceec5b5f8679}" />
<ID Name="DeviceConnected" Value="20" />
<ID Name="DeviceDisconnected" Value="30" />
Expand Down
11 changes: 10 additions & 1 deletion VisualStudio.Extension-2022/Rules/None.BrowseObject.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,14 @@

<BoolProperty Name="Visible"
Visible="false" />

<!--nanoFramework deployment rule-->
<Category Name="nanoFramework" DisplayName="nanoFramework" Description=".NET nanoFramework properties" />
<StringProperty Category="nanoFramework" Name="NF_StoragePath" DisplayName="Storage destination path" Visible="true" Description="Destination path in target storage, including file name.">
<StringProperty.DataSource>
<DataSource HasConfigurationCondition="False"
PersistedName="NF_StoragePath"
Persistence="UserFile"
SourceOfDefaultValue="AfterContext" />
</StringProperty.DataSource>
</StringProperty>
</Rule>
18 changes: 18 additions & 0 deletions VisualStudio.Extension-2022/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,24 @@
"Microsoft.VisualStudio.Interop": "17.5.33428.366"
}
},
"csharp.assemblyinfotemplate": {
"type": "Project"
},
"csharp.blankapplication-vs2022": {
"type": "Project"
},
"csharp.classlibrary-vs2022": {
"type": "Project"
},
"csharp.classtemplate": {
"type": "Project"
},
"csharp.resourcetemplate": {
"type": "Project"
},
"csharp.testapplication-vs2022": {
"type": "Project"
},
"nanoFramework.Tools.BuildTasks": {
"type": "Project",
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions nanoFramework.Tools.VisualStudio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ Global
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
CSharp.TestApplication\CSharp.TestApplication.Shared.projitems*{0a06b3c4-5813-439e-85ef-6d584a4e03ed}*SharedItemsImports = 13
nf-debugger\nanoFramework.Tools.DebugLibrary.Shared\nanoFramework.Tools.DebugLibrary.Net.projitems*{101d57ad-d22f-4905-a992-de15e723f164}*SharedItemsImports = 5
CSharp.TestApplication\CSharp.TestApplication.Shared.projitems*{3040ba82-56cc-4189-a26c-cabb4b6b7b87}*SharedItemsImports = 4
nf-debugger\nanoFramework.Tools.DebugLibrary.Shared\nanoFramework.Tools.DebugLibrary.Net.projitems*{31472cae-4b1a-4ab9-9b2a-8f28dbe01bcf}*SharedItemsImports = 13
CSharp.ClassLibrary\CSharp.ClassLibrary.Shared.projitems*{4aa9a693-ff7c-4f84-b0ce-28a7ee009471}*SharedItemsImports = 4
CSharp.BlankApplication\CSharp.BlankApplication.Shared.projitems*{572121bd-e972-4bf7-abf1-78251dde1181}*SharedItemsImports = 4
CSharp.ClassLibrary\CSharp.ClassLibrary.Shared.projitems*{5dc66510-7529-477b-98a8-733a792ddd14}*SharedItemsImports = 4
Expand All @@ -303,6 +305,7 @@ Global
vs-extension.shared\vs-extension.shared.projitems*{b16737e2-4b5d-4048-a740-2bb1df462637}*SharedItemsImports = 13
CSharp.BlankApplication\CSharp.BlankApplication.Shared.projitems*{c5a2cf84-5591-4c33-8cf7-6c949531bfb1}*SharedItemsImports = 13
CSharp.BlankApplication\CSharp.BlankApplication.Shared.projitems*{cd034c5a-a9eb-4c8e-b163-0ba9619cd122}*SharedItemsImports = 4
metadata-processor\MetadataProcessor.Shared\MetadataProcessor.Shared.projitems*{e32f7d15-2499-440c-8026-4d5ee1c5ec3a}*SharedItemsImports = 4
vs-extension.shared\vs-extension.shared.projitems*{e3e5b359-8e18-4b7d-8469-f93c6867d712}*SharedItemsImports = 4
CSharp.ClassLibrary\CSharp.ClassLibrary.Shared.projitems*{faa194f0-5c3b-46c7-977b-d2a84444bf80}*SharedItemsImports = 13
EndGlobalSection
Expand Down
44 changes: 44 additions & 0 deletions vs-extension.shared/DeployProvider/DeployProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,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<Microsoft.Build.Evaluation.Project>)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
Expand Down Expand Up @@ -369,6 +372,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
_viewModelLocator.DeviceExplorer.LastDeviceConnectedHash = 0;
}
Expand Down
Loading