How do I get the output directories from the last build? - build

Let's say I've got a solution with one or more projects, and I've just kicked off a build using the following method:
_dte.Solution.SolutionBuild.Build(true); // EnvDTE.DTE
How can I get the output paths for each project that just built? For example...
c:\MySolution\Project1\Bin\x86\Release\
c:\MySolution\Project2\Bin\Debug

Please don't tell me this is the only way...
// dte is my wrapper; dte.Dte is EnvDte.DTE
var ctxs = dte.Dte.Solution.SolutionBuild.ActiveConfiguration
.SolutionContexts.OfType<SolutionContext>()
.Where(x => x.ShouldBuild == true);
var temp = new List<string>(); // output filenames
// oh shi
foreach (var ctx in ctxs)
{
// sorry, you'll have to OfType<Project>() on Projects (dte is my wrapper)
// find my Project from the build context based on its name. Vomit.
var project = dte.Projects.First(x => x.FullName.EndsWith(ctx.ProjectName));
// Combine the project's path (FullName == path???) with the
// OutputPath of the active configuration of that project
var dir = System.IO.Path.Combine(
project.FullName,
project.ConfigurationManager.ActiveConfiguration
.Properties.Item("OutputPath").Value.ToString());
// and combine it with the OutputFilename to get the assembly
// or skip this and grab all files in the output directory
var filename = System.IO.Path.Combine(
dir,
project.ConfigurationManager.ActiveConfiguration
.Properties.Item("OutputFilename").Value.ToString());
temp.Add(filename);
}
This makes me want to retch.

You can get to the output folder(s) by traversing the file names in the Built output group of each project in EnvDTE:
var outputFolders = new HashSet<string>();
var builtGroup = project.ConfigurationManager.ActiveConfiguration.OutputGroups.OfType <EnvDTE.OutputGroup>().First(x => x.CanonicalName == "Built");
foreach (var strUri in ((object[])builtGroup.FileURLs).OfType<string>())
{
var uri = new Uri(strUri, UriKind.Absolute);
var filePath = uri.LocalPath;
var folderPath = Path.GetDirectoryName(filePath);
outputFolders.Add(folderPath.ToLower());
}

Related

Embedded Node execute .node file

I've built an embedded instance of Node using the Embed_Test example from the Node repository.
Using this instance, I am trying to execute some C++ code.
I have a generated .node and .dll, and I have webpack'd my Javascript file.
When I run,
node dist/bundle.js
It runs fine. However, when I start up my embedded NodeJS application and attempt to run bundle.js, I get the following error (it's as if it cannot load the .node file?):
TypeError: Cannot read property 'testCppCode' of undefined
at evalmachine.<anonymous>:154:2305
at s.handle_request (evalmachine.<anonymous>:120:782)
at s (evalmachine.<anonymous>:113:879)
at p.dispatch (evalmachine.<anonymous>:113:901)
at s.handle_request (evalmachine.<anonymous>:120:782)
at evalmachine.<anonymous>:106:2533
at Function.v.process_params (evalmachine.<anonymous>:106:3436)
at g (evalmachine.<anonymous>:106:2476)
at evalmachine.<anonymous>:259:218
at s.handle_request (evalmachine.<anonymous>:120:782)
This is my App.js, before a webpack:
var myArgs = process.argv.slice(2);
var ip = myArgs.length >= 1 ? myArgs[0] : "localhost";
var port = myArgs.length >= 2 ? myArgs[1] : "5555";
var fs = require("fs");
var path = require("path");
const express = require("express");
var addon = require("../build/Release/test.node");
const server = express();
server.get("/", (req, res) => {
var res = addon.testCppCode("Sample", function (err, cpp) {
var capabilitiesResult = cpp;
if (err) {
console.log("Error!");
console.log(err);
console.log(cpp);
} else {
console.log("Success!");
}
});
});
I've tried sticking the test.node and test.dll in the same folder as the embedded instance of node, I've tried putting it in the same dir as the webpack, I've tried sticking it in a relative dir to the embedded node (so it would be at ../build/Release/) -- but the error is always the same. What do I need to do in order to get it to "see" the .node file?

How to generate icon for onesignal using ionic

I am using ionic 2.
I need generate the icon for one signal notification.
I tried to this
Add a file to your hooks directory inside the after_prepare folder called 030_copy_android_notification_icons.js
Put the following code in it:
var filestocopy = [{
"resources/android/icon/drawable-hdpi-icon.png":
"platforms/android/res/drawable-hdpi/ic_stat_onesignal_default.png"
}, {
"resources/android/icon/drawable-mdpi-icon.png":
"platforms/android/res/drawable-mdpi/ic_stat_onesignal_default.png"
}, {
"resources/android/icon/drawable-xhdpi-icon.png":
"platforms/android/res/drawable-xhdpi/ic_stat_onesignal_default.png"
}, {
"resources/android/icon/drawable-xxhdpi-icon.png":
"platforms/android/res/drawable-xxhdpi/ic_stat_onesignal_default.png"
}, {
"resources/android/icon/drawable-xxxhdpi-icon.png":
"platforms/android/res/drawable-xxxhdpi/ic_stat_onesignal_default.png"
} ];
var fs = require('fs');
var path = require('path');
// no need to configure below
var rootdir = process.argv[2];
filestocopy.forEach(function(obj) {
Object.keys(obj).forEach(function(key) {
var val = obj[key];
var srcfile = path.join(rootdir, key);
var destfile = path.join(rootdir, val);
//console.log("copying "+srcfile+" to "+destfile);
var destdir = path.dirname(destfile);
if (fs.existsSync(srcfile) && fs.existsSync(destdir)) {
fs.createReadStream(srcfile).pipe(
fs.createWriteStream(destfile));
}
});
});
I have no idea.
Kindly advice me,
Thanks
I have faced with same issue. Your way is correct, putting 030_copy_android_notification_icons.js file under {root}/hooks/after_prepare. Also note that, filename is not important.
Then to run script you need to run below comment:
ionic cordova prepare android
With this, your script will be run. But maybe your problem may be similar to mine. If you use windows, while coping files from resources/android/icon/ to platforms/android/res/, because of missing of target folders, script is not able to copy operation. That's why a simple code should be added to code.
var destdir = path.dirname(destfile);
if (!fs.existsSync(destdir)){
fs.mkdirSync(destdir);
}

Properly babel transpile a file in ember-cli-build withing additional tree

I have some files in my project that I would like to move out of the normal app tree and only load in certain situations. Currently I used broccoli-stew to move the file and broccoli-babel-transpiler to transpile the destination file. However when I do this I end up with an extra default object on the imported files.
this code gets added to the top
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _Ember = _interopRequireDefault(_ember);
and this causes me to have to write the source file with references to ember as Ember["default"].Object etc. Would like to not have any odd references in the source files that makes it harder for other developers to understand.
This is my current ember-cli-build.js file
/* global require, module */
var stew = require('broccoli-stew');
var esTranspiler = require('broccoli-babel-transpiler');
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
storeConfigInMeta: false
});
var additionalTrees = [];
var appTree = app.appAndDependencies();
if (EmberApp.env() !== "production") {
var jQuery = stew.find(appTree, "bower_components/jquery/dist/jquery.min.js");
jQuery = stew.mv(jQuery, "bower_components/jquery/dist/jquery.min.js", "assets/jquery.js");
additionalTrees.push(jQuery);
}
function extractRouter(fileName) {
var router = stew.find(appTree, 'mobile-web/'+ fileName + '.js');
router = esTranspiler(router, {
modules: "amd",
moduleIds: true,
moduleId: "mobile-web/router"
});
router = stew.mv(router, 'mobile-web/'+ fileName + '.js', 'assets/'+ fileName + '.js');
additionalTrees.push(router);
}
extractRouter('router');
extractRouter('secure-router');
return app.toTree(additionalTrees);
};
Try configure your esTranspiler to use modules: "amdStrict":
router = esTranspiler(router, {
modules: "amdStrict",// here
moduleIds: true,
moduleId: "mobile-web/router"
});
It's similar to "commonStrict" as described in the docs. The amdScrict exists in the source code here.

How to list subdirectories in Azure blob storage

MS has announced directory like blob storage, and I'm trying to use it like directories.
Having save some blobs by names:
Common\Service1\Type1\Object1
Common\Service1\Type1\Object2
Common\Service1\Type2\Object1
Common\Service1\Type2\Object2
Common\Service1\Type3\Object1
Common\Service1\Type3\Object2
Common\Service1\Type3\Object3
I'd like to have possibility to enumerate subdirectories, e.g. I have blobclient referenced to Common container name, and I would like to get subcontainers list Type1, Type2, Type3. Is it possible to get list of subdirectories in some directory. Using ListBlobs returns full list of blobs within current container.
If you would like to list all "subdirectories" in "Common\Service1" directory you can use something like this:
var directory = blobContainer.GetDirectoryReference(#"Common/Service1");
var folders = directory.ListBlobs().Where(b => b as CloudBlobDirectory != null).ToList();
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}
Full code sample:
var random = new Random();
CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
var cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer blobContainer = cloudBlobClient.GetContainerReference("test-container");
blobContainer.CreateIfNotExists();
string[] objects = new[]
{
#"Common\Service1\Type1\Object1", #"Common\Service1\Type1\Object2", #"Common\Service1\Type2\Object1",
#"Common\Service1\Type2\Object2", #"Common\Service1\Type3\Object1", #"Common\Service1\Type3\Object2",
#"Common\Service1\Type3\Object3"
};
foreach (var newObject in objects)
{
var newBlob = blobContainer.GetBlockBlobReference(newObject);
var buffer = new byte[1024];
random.NextBytes(buffer);
newBlob.UploadFromByteArray(buffer,0,buffer.Length);
}
var directory = blobContainer.GetDirectoryReference(#"Common/Service1");
var folders = directory.ListBlobs().Where(b => b as CloudBlobDirectory != null).ToList();
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}
This will output Uri for Type1,Type2 and Type3 directory.
Building on b2zw2a's answer:
The # is only needed when using \, not /.
Don't chain ToList() after ListBlobs(). ListBlobs() provides lazy loading and will give you better perf.
Use OfType<CloudBlobDirectory>() to filter out only the type you want
Giving you:
var directory = blobContainer.GetDirectoryReference("Common/Service1");
var folders = directory.ListBlobs().OfType<CloudBlobDirectory>();
foreach (var folder in folders)
{
Console.WriteLine(folder.Uri);
}
var nameList=logoContainer.ListBlobs().Where(b => b as CloudBlobDirectory != null).Select(x => x.Uri + "").ToList();
By using this you can get all the filenames in a single query.

Visual Studio Preprocessor - access compiler flags

I am currently converting a Qt project from being .pro file based to Visual Studio based.
In the original .pro file I have used the following
LIBSTR = '\\"$${LIBS}\\"'
DEFINES += LIBRARIES=\"$${LIBSTR}\"
Which allows me to see what libraries were used in my application.
I would like to replicate this in Visual Studio but cannot see how to do this.
1) Add the configure.h to the project
#pragma once
#define LIBRARIES TEXT("")
2) Add $${LIBS} to the Project properties -> Linker -> Input -> Additional Dependencies section.
3) Add to the Project properties -> Build Events -> Pre-Build Event a script like:
cscript /nologo configure.js $(ProjectPath) $(ConfigurationName) $(PlatformName)
configure.js:
var proj = WScript.Arguments(0);
var conf = WScript.Arguments(1);
var platf = WScript.Arguments(2);
var configFile = "configure.h";
try {
var doc = new ActiveXObject("msxml2.DOMDocument.6.0");
doc.async = false;
doc.resolveExternals = false;
doc.validateOnParse = false;
doc.load(proj);
var node = doc.selectSingleNode("//Configuration[#Name=\""+conf+"|"+platf+"\"]/Tool[#Name=\"VCLinkerTool\"]");
var attr = node.attributes.getNamedItem("AdditionalDependencies");
var libStr = attr ? attr.value : "";
var fso = new ActiveXObject("Scripting.FileSystemObject");
var aFile = fso.GetFile(".\\" + configFile);
var fStream = aFile.OpenAsTextStream(1);
var re = new RegExp("^\\s*#\\s*define\\s+LIBRARIES\\s+");
var done = false;
var text = "";
while (!fStream.AtEndOfStream) {
var aStr = fStream.ReadLine();
if (!done && re.test(aStr)) {
aStr = "#define LIBRARIES TEXT(\"" + libStr.replace(/(\\|")/g, "\\$1") + "\")";
done = true;
}
text += aStr + "\n";
}
fStream.Close();
fStream = aFile.OpenAsTextStream(2);
fStream.Write(text);
fStream.Close();
} catch (e) {
WScript.Echo("Error:");
WScript.Echo(e.description);
WScript.Quit(1);
}
WScript.Echo("Done");
WScript.Quit(0);
Then after you'll start the build the configure.h file will be updated and LIBRARIES will contain all libs you defined for the current build configuration and platform.