Skip to content
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
44 changes: 44 additions & 0 deletions src/dotnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as os from 'os';
import { Executor } from "./executor";
import * as cp from 'child_process';
import * as vscode from 'vscode';
import * as fs from "fs";

const mdpBuildProperties = ' -p:NFMDP_PE_Verbose=false -p:NFMDP_PE_VerboseMinimize=false';

Expand Down Expand Up @@ -79,6 +80,49 @@ export class Dotnet {
Executor.runInTerminal(`nanoff --update ${cliArguments}`);
}
}

/**
* First finds all of the content files from the nfproj file that are set to PreserveNewest
* or Always. Generates a temporary deploy.json file containing those files. Then deploys those files
* to the selected device. Then it removes the temporary deploy.json
* @param fileUri absolute path to *.sln
* @param serialPath path to connected nanoFramework device (e.g. COM4 or /dev/tty.usbserial*)
* @param toolPath absolute path to root of nanoFramework extension
* @param storagePrefix drive letter to use for storage (`I:\\` for internal, `E:\\` for USB, `D:\\` for SD Card)
*/
public static async deployFiles(fileUri: string, serialPath: string, toolPath: string, storagePrefix: string = 'I:\\') {
if (fileUri) {
const outputDir = path.dirname(fileUri) + '/OutputDir/';
const cliBuildArguments = 'getItem:Content > contentfiles.json';
var binaryFile;

binaryFile = await executeMSBuildAndFindBinaryFile(fileUri, cliBuildArguments);

await fs.readFile('contentFiles.json', 'utf8', async function (err: any, contentItems: any) {
if (err) {
return err;
}

const itemsToCopy = contentItems.Items.Content.filter((item: any) => item.CopyToOutputDirectory !== 'Never');

let deploy = {
serialPort: serialPath,
files: itemsToCopy.map((item: any) => {
return {
DestinationFilePath: `${storagePrefix}${item.Identity}`,
SourceFilePath: item.FullPath
};
})
};

await fs.writeFile('tempdeploy.json', deploy, { flag: 'w'});
Executor.runInTerminal('nanoff --filedeployment tempdeploy.json');
});

await fs.unlink('contentfiles.json');
await fs.unlink('tempdeploy.json');
}
}
}

/**
Expand Down
6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ export async function activate(context: vscode.ExtensionContext) {
const projectType = await chooseProjectType();
NfProject.AddProject(path, projectName, projectType, nanoFrameworkExtensionPath);
}));

context.subscriptions.push(vscode.commands.registerCommand('vscode-nanoframework.nffiledeploy', async (fileUri: vscode.Uri,) => {
const path = await solvePath(fileUri, workspaceFolder);
const serialPath = await chooseSerialPort(nanoFrameworkExtensionPath);
Dotnet.deployFiles(path, serialPath, nanoFrameworkExtensionPath, 'I:\\');
}));
}

/**
Expand Down
Loading