I'm using the .NET Client Libraries for VSTS/TFS 2015 to programmatically create a build definition based off of a template that I've grabbed in another team project.
I can get a build definition template (2.0) by using:
BuildDefinitionTemplate builddeftemplate = buildHttpClient.GetTemplateAsync(teamProject, templateId).Result;
And I can create a build definition by using:
BuildDefinition builddef = new BuildDefinition();
builddef.Project = newTeamProject;
But there doesn't look like a way to pass in a template as a property of the build definition, nor create a build definition from the template.
When looking at the documentation for the REST API, the GET request actually looks like it returns a lot of JSON:
{
"id": "vsBuild",
"name": "Visual Studio",
"canDelete": false,
"category": "Build",
"iconTaskId": "71a9a2d3-a98a-4caa-96ab-affca411ecda",
"description": "Build and run tests using Visual Studio. This template requires that Visual Studio be installed on the build agent.",
"template": {
"build": [
{
"enabled": true,
"continueOnError": false,
"alwaysRun": false,
"task": {
"id": "71a9a2d3-a98a-4caa-96ab-affca411ecda",
"versionSpec": "*"
},
"inputs": {
"solution": "**\\*.sln",
"msbuildLocation": "",
"vsLocation": "",
"msbuildArgs": "",
"platform": "$(BuildPlatform)",
"configuration": "$(BuildConfiguration)",
"clean": "false"
}
},
...
So I think that it might be possible to only grab parts of the returned template as a JSON object and pass through a POST of the build definition with those parts, but it seems like that would have to solely be the REST API route.
Is this possible with the .NET Client Libraries? Or is there an easier way that I might have missed?
There isn't a way to pass in a template as a property of the build definition. However, there's another way to achieve it. You can clone/import/export build definition between team projects through .net libraries.
var cred = new VssCredentials(new WindowsCredential(new NetworkCredential(username, password)));
var buildClient = new BuildHttpClient(new Uri(collectionURL, UriKind.Absolute), cred);
var buildDef = (await buildClient.GetDefinitionAsync(sourceProj, buildDefId)) as BuildDefinition;
buildDef.Project = null;
buildDef.Name += "_clone";
await buildClient.CreateDefinitionAsync(buildDef, targetProj);
From above code you can authenticate to the team server and retreive the build definition object from the source project by the providing project name and the build definition id.
And then you need to remove the reference to the project. Since build definition contains a reference to the project it would not be possible to import it into a different project. Finally create a new build definition in target project providing the definition objecte retreived from previous project.
Next step is to export the build definition to a file so we can latter import it. By using a json serializer to serialize the build definition and save it to a file.
var buildDef = (await buildClient.GetDefinitionAsync(project, buildDefId)) as BuildDefinition;
buildDef.Project = null;
File.WriteAllText(filePath, JsonConvert.SerializeObject(buildDef));
Finally add a import method, more details please refer this link
if (!File.Exists(filePath))
throw new FileNotFoundException("File does not exist!", filePath);
Console.WriteLine($"Importing build definition from file '{filePath}' to '{project}' project.");
var buildDef = JsonConvert.DeserializeObject<BuildDefinition>(File.ReadAllText(filePath));
buildDef.Name = newBuildName;
await buildClient.CreateDefinitionAsync(buildDef, project);
Related
I am planning to use Playwright .NET to perform automated UI testing in a C# dotnet project. The issue is that I would like to have global configuration that can be set rather than needing to define the same settings repeatedly in the context of each test, but I cannot seem to find any working examples.
The documentation at playwright.dev implies that I should be able to simply include a "playwright.config.js" file at the root of the project, but no clear definition of what the content of that file should be. I have experimented with the example provided for Playwright Node.js, using:
import { PlaywrightTestConfig } from '#playwright/test';
const config: PlaywrightTestConfig = {
use: {
// Browser options
headless: false,
slowMo: 50,
// Context options
viewport: { width: 1280, height: 720 },
ignoreHTTPSErrors: true,
// Artifacts
screenshot: 'only-on-failure',
//video: 'retry-with-video',
},
outputDir: "C:\\stuff\\screenshots",
preserverOutput: 'always',
quiet: false,
};
export default config;
However, these settings do not seem to be applied and there is no indication that the playwright.config.js file is either loading or failing.
Any help or a simple example to get me pointed in the right direction would be much appreciated.
LaunchAsync expects a BrowserTypeLaunchOptions class. You could have that object serialized in a JSON file, parse it and pass that options instance as an argument.
I'd like to have ASP.NET core 2.2 with TypeScript and Signalr, but I do not know, how to correctly setup project.
I have installed #aspnet/signalr npm package to project root withnpm install #aspnet/signalr. So my project root looks like this:
Controllers/
Models/
node_modules/
Properties/
TypeScript/
Views/
wwwroot/
appsettings.Development.json
appsettings.json
MyProject.csproj
package-lock.json
package.json
Program.cs
Startup.cs
tsconfig.json
Having this TypeScript/home.ts file:
import * as signalR from "#aspnet/signalr";
const connection = new signalR.HubConnectionBuilder().withUrl("/gameHub").build();
connection.on("ReceiveMessage", function (user, color) {
console.log("color " + color + "; user " + user);
let canvas = <HTMLCanvasElement>document.getElementById(user).getElementsByClassName("board")[0];
let context = canvas.getContext("2d");
context.fillStyle = color;
context.fillRect(0, 0, 200, 200);
});
And finally my tsconfig.json file:
{
"compileOnSave": true,
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": false,
"sourceMap": true,
"target": "es2017",
"outDir": "wwwroot/js"
},
"exclude": [
"node_modules",
"wwwroot"
]
}
When I use in tsconfig.json "target": "es2017",, then VS cannot find #aspnet/signalr and I can't run project. When I switch it to "target": "es5",, then VS can find #aspnet/signalr, but it generates home.js with following line: Object.defineProperty(exports, "__esModule", { value: true }); and it throws an error in browser.
I guess that my tsconfig.json is not properly setup. Also I would like to use ES6 modules in browser if possible (https://www.sitepoint.com/using-es-modules/)
Try to follow this tutorial
Normaly you have to target es5 to run in web project in the browser. he turtorial show you how to setup typescript with webpack because we need to compile ts to js
Please let me know if you need any help
I want to get all informations about files from my github repository using octokit
projectis: http://octokitnet.readthedocs.org/en/latest/contributing/
Updated:
what I thought I can do is
getAllFilesFromRepository
that will return json with something like example below for all files in repository
{
"type": "symlink",
"target": "/path/to/symlink/target",
"size": 23,
"name": "some-symlink",
"path": "bin/some-symlink",
"sha": "452a98979c88e093d682cab404a3ec82babebb48",
"url": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
"git_url": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
"html_url": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink",
"download_url": "https://raw.githubusercontent.com/octokit/octokit.rb/master/bin/some-symlink",
"_links": {
"git": "https://api.github.com/repos/octokit/octokit.rb/git/blobs/452a98979c88e093d682cab404a3ec82babebb48",
"self": "https://api.github.com/repos/octokit/octokit.rb/contents/bin/some-symlink",
"html": "https://github.com/octokit/octokit.rb/blob/master/bin/some-symlink"
}
}
Please note
I do not want to download any files at all or write query with multiple calls to retrieve the data.
I'm not sure I understand the question, but please read the Getting Started guide first around the setup you need.
This is an example of how to download the contents of a given repository:
var github = new GitHubClient(...); // TODO: other setup
var contents = await github
.Repository
.Content
.GetAllContents("octokit", "octokit.net");
...
var docs = await github
.Repository
.Content
.GetAllContents("octokit", "octokit.net", "docs");
Change the values to suit the repository you're interested in. If you want to download a non-default branch, use GetAllContentsByRef instead.
GetAllContents method would work fine but one small issue is that it would not iterate recursively through all the sub-folders in your repository. It gives only the files and folders present in the top-level. If you want to list out all the files of your repository, I would suggest you to use the GetRecursive method as follows:
var trees = _gitHubClient.Git.Tree.GetRecursive(_config.Owner, _config.RepositoryId, <<APPROPRIATE SHA>>).Result;
You can get the SHA for the latest commit or as per your requirement.This method would give you a tree response which has sufficient details such as the SHA, Path, Type and Size.
I want to create an ext.js store that can be shared across c# projects. I defined my store in the Services project under Scripts/Store/Hierarchies.js. The store is named NCS.store.Hierarchies.
Ext.define('NCS.store.Hierarchies', {
requires: [
'Ext.data.proxy.Proxy',
'Ext.data.Operation',
'Ext.data.reader.Json',
'NCS.store.SelectedHierarchies'
],
In a different c# project I now want to reference this store-
Ext.widget({
id: 'hierarchyPanel',
xtype: 'panel',
border: true,
frame: true,
title: 'Hierarchy Selector',
layout: {
type: 'hbox',
pack: 'start',
align: 'stretch'
},
collapsible: true,
items: NCS.store.Hierarchies.getComboArray().concat(
Ext.create('Ext.Button', {
id: 'hierarchyClear',
text: 'Clear'
})),
renderTo: this.constants.hierarchiesId,
listeners: {
show: {
fn: function (t, o) {
t.doLayout();
}
}
}
});
How do I properly reference this store? Currently I'm getting a not found error (it's looking in the current c# project url instead of the one that actually contains the store).
> GET
> http://localhost/Orchard/NCS.Reporting.PODS/NCS/store/Hierarchies.js?_dc=1405085182757
> 404 (Not Found)
I think it should be looking
http://localhost/Orchard/NCS.Services.PODS/NCS/store/Hierarchies.js?_dc=1405085182757
Also since it's looking under NCS/store I'm wondering if I need to change the folder layout to match my naming convention.
I would consider mapping the folder where the scripts are stored as a virtual directory in IIS so that the web server can serve them in response to web requests.
You can use the ExtJs Loader object -
// load up all of our dependencies
Ext.Loader.setConfig({
enabled: true,
paths: {
'NCS': Config.RootUrl + 'Modules/NCS.Services.PODS/Scripts'
}
});
I need to specify where to find NCS for ExtJS to locate the correct file. Now that I have the NCS path loaded I can use the code above to reference NCS.store.Hierarchies.
I've been working on converting my ElasticSearch (ES) 0.9 code to work with ES 1.0. This has required an upgrade of NEST to the latest pre-release version.
I've been trying to bulk index a set of child documents. I've set up their mapping as:
"stocks": {
"_parent": {
"type": "products"
},
"_timestamp": {
"enabled": true
},
"properties": {
"id": {
"type": "integer",
"index": "not_analyzed"
},
"stock": {
"type": "integer",
"index": "not_analyzed"
}
}
}
This was created in ES 0.9. When I've put this into ES 1.0, it automatically adds a Routing property with 'Required' set to 'true'. A search on Google suggests that this was always required to enable a parent-child document setup but the property never explicitly appeared when I examined the documents in my 0.9 shard.
"Ok..." I think to myself. Next, I have the following code block for NEST:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Parent = p.id.ToString()});
IElasticsearchResponse c = ec.IndexMany(bulkParams, null, "stocks").ConnectionStatus;
This returns a NullReferenceException. After some guesswork I added the Id parameter into the BulkParameters:
var bulkParams = postQueue.Select(p => new BulkParameters<Stock>(p) { Id = p.id.ToString(), Parent = p.id.ToString()});
Which seems to work, but the request returns a error response from ES:
400 Bad Request with JSON error message:
error=RoutingMissingException[routing is required for [test_index]/[stocks]/[xx]]
(where xx is the id of the document)
I'm assuming I have to insert a Routing string somewhere, but I do not know where. I've tried adding a 'Routing' parameter into the BulkParameters but that did not work at all. Can anyone please advise?
The support for IndexMany() with wrapped BulkParameters has been removed in NEST 1.0.0 beta 1
If you want to use a bulk with more advanced parameters you now have to use the Bulk() command.
The beta sadly still shipped with the BulkParameters class in the assembly
This has since been removed in the develop branch and will be released in the next beta update.
So what happens now is that you are actually indexing "bulkparameters``1``" type documents and not "stock" with proper individual bulk metadata set.
See here for an example on how to use Bulk() to index many objects at once while configuring advanced parameters for individual items.