I created a method to update an existing Test Suite. The method executes without any exception or error. However, the Test Suite is not getting updated with the list of configurations nor is the "Inherit Default Configurations" getting set to false.
public TestSuite UpdateTestSuiteConfigurations(Guid projectId, int planId, int suiteId, List<int> configIds)
{
var VstsConfigurationIds = new List<ShallowReference>();
foreach (var item in configIds)
{
VstsConfigurationIds.Add(new ShallowReference(item.ToString()));
}
var SuiteToUpdate = new SuiteUpdateModel(inheritDefaultConfigurations: false, defaultConfigurations: VstsConfigurationIds.ToArray());
var VSTS = new TestManagementHttpClient(URI, Credentials);
var TestSuiteUpdate = VSTS.UpdateTestSuiteAsync(SuiteToUpdate, projectId, planId, suiteId).Result;
VSTS.Dispose();
return TestSuiteUpdate;
}
Can someone please point out the issue? My expectation is that after updating the Test Suite should not inherit default configurations and should have the provided configurations assigned to it. I have verified that the configurations are present and that I am using the correct configuration ids.
I have not created a shallow reference before so maybe that is the issue?
I can reproduce this issue with 15.112.1 version of Microsoft.TeamFoundationServer.ExtendedClient package, but works fine with latest version (15.131.0-preview).
So, you can create a new project and install latest version package, then try again.
Related
I've been tasked to create work items and branches in VSTS from within our C# application. I've seen many examples for creating a work item and I was able to do it myself using the libraries (Microsoft.VisualStudio.Services.Client & Microsoft.TeamFoundationServer.Client). So far I've only seen one example creating a branch in TFS 2013, but I could not follow along since the CreateBranch method is now obsolete (according to the documentation). I was also unable to find the TeamFoundationServer class in these libraries.
public void CreateBranchWithComment(string serverUrl, string sourcePath, string targetPath, string comment)
{
var tfs = new TeamFoundationServer(serverUrl);
var vcServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
var changesetId = vcServer.CreateBranch(sourcePath, targetPath, VersionSpec.Latest);
var changeset = vcServer.GetChangeset(changesetId);
changeset.Comment = comment;
changeset.Update();
}
Is it still possible to create branches via the REST API or libraries? If so, could you please point me in the right direction?
It turns out that this functionality is only available from the SOAP methods. I missed the TfsTeamProjectCollection class when I read the documentation. Because I was solely focusing on REST API, I paid little attention to anything related to the SOAP methods and examples.
According to the documentation the TeamFoundationServer class is obsolete since Visual Studio 2010, however the CreateBranch method is still available in the VersionControlServer class.
To retrieve an instance of the VersionControlServer class, you must call GetService from a TfsTeamProjectCollection instance. Include the Microsoft.TeamFoundationServer.ExtendedClient Nuget package.
For Example:
var server = new TfsTeamProjectCollection(accountUri, new VssBasicCredential(string.Empty, personalAccessToken));
var vcServer = server.GetService<VersionControlServer>();
/*
* See documentation for this class at:
* https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver(v=vs.120).aspx
*/
var changesetId = vcServer.CreateBranch("$/Demo/Main","$/Demo/Dev/Branch", VersionSpec.Latest, null, "Branch Comment", null, null, null);
See the TfsTeamProjectCollection class documentation for more information.
There is a set of rules that should be applied while moving solutions from one instance to another, so there is an idea to use a custom tool that will make all changes, export and import solutions to another instance. The question is next:
How could "solution upgrade applying" be implemented with C#?
Importing "as holding" easily could be done by setting (CRM 2016 SDK)
var import = new ImportSolutionRequest();
import.HoldingSolution = true;
this allows to have a holding solution in a target environment, but after some tests we still can't "Apply" this upgrade for the previously installed solution.
Thank you in advance.
After you have imported the holding solution you can upgrade it using a DeleteAndPromoteRequest.
A basic example:
public Guid UpgradeSolution(string solutionUniqueName, IOrganizationService service)
{
var request = new DeleteAndPromoteRequest
{
UniqueName = solutionUniqueName
};
var response = (DeleteAndPromoteResponse)service.Execute(request);
return response.SolutionId;
}
In the DeleteAndPromoteResponse the SolutionId property holds the Guid of the promoted solution.
I am working on a solution where I want to get parameters from a Builddefinition per Code. When I hit it, I get an error message "No build definition was found for
team project ToyStory with name Spass-mit-Flaggen."
The used code is written below:
var tfsCreds = new TfsClientCredentials(new WindowsCredential(), false);
var tpc = new TfsTeamProjectCollection(new Uri(options.CollectionUri), tfsCreds);
var buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer));
var buildDetail = buildServer.GetBuild(new Uri(options.BuildUri));
var buildDefinition = buildServer.GetBuildDefinition(
buildDetail.TeamProject,
options.BuildDefinition);
The options object contains all program parameters. In this case they are the following strings:
options.CollectionUri == "http://tfs-test:8080/tfs/Test/"
options.BuildUri == "vstfs:///Build/Build/85"
options.BuildDefiniton == "Spass-mit-Flaggen"
Has someone an idea what's going wrong here?
Thanks in advance
You're using the old SOAP API for accessing builds. The new build system introduced in TFS 2015 doesn't use SOAP messaging, it has a totally separate REST API. You'll need to use the REST API, available in easily-consumable object model form on NuGet.
I'm new to extending Visual Studio and I'm trying to find way to find which source control system is used by current solution.
I created VsPackage project and I am able to obtain reference to solution via IVsSolution and to hook up to solution events via IVsSolutionEvents.
Inside OnAfterSolutionOpen (or possibly some other if there's an alternative) I would like to act differently basing on whether the solution uses TFS or Git or something else. How can I obtain this information?
I plan to support as many Visual Studio versions as possible, but if it isn't possible I would like to support at least VS2012 and higher.
Ok, after several hours of digging I've found a solution to this. Thanks to the article of Mark Rendle and the source code for his NoGit extension I've found, that the list of registered source control plugins is located in registry: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\SourceControlProviders (in case of VS 2013).
So now, we can have both plugin guid, and the name of the provider. This sample code can fetch those values:
var key = #"Software\Microsoft\VisualStudio\" + "12.0" + #"_Config\SourceControlProviders";
var subkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(key);
var providerNames = subkey.GetSubKeyNames().Dump();
var dict = new Dictionary<Guid, String>();
foreach (var provGuidString in subkey.GetSubKeyNames())
{
var provName = (string)subkey.OpenSubKey(provGuidString).GetValue("");
dict.Add(Guid.Parse(provGuidString), provName);
}
Now, there are two ways I've found to obtain guid of currently active provider.
important update: Apparently the second way of obtaining currently active plugin does not work as expected. I strongly advise using first solution.
This is the way that bases on the extension mentioned earlier:
var getProvider = GetService(typeof(IVsRegisterScciProvider)) as IVsGetScciProviderInterface;
Guid pGuid;
getProvider.GetSourceControlProviderID(out pGuid);
Or we can just go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0\CurrentSourceControlProvider and get the default value of this key:
var key2 = #"Software\Microsoft\VisualStudio\12.0\CurrentSourceControlProvider";
var guidString = (string)Microsoft.Win32.Registry.CurrentUser.OpenSubKey(key2).GetValue("");
var currentGuid = Guid.Parse(guidString);
Now we just take var activeProviderName = dict[currentGuid]; and that's all.
I am using NUnit with Visual Studio Express Edition 2010 for C#, Now, normally test works fine. But whenever I try to use Massive.cs, which is open source api to access database. Test fails from that file only. Now, if I run the application, api is working fine. I have created a different library file to access data base.
I seriously don't understand the error. It is just giving error that object reference is not set to an object. But if I run the code, it works fine. I am using dynamic keyword as shown in link of api above. Does that making problem with NUnit ?
Is there any other way to test in this type of Scenarios?
Here are the further details of the code,
Test class is like this
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var items = item.All();
Assert.AreEqual("Maggi", items.FirstOrDefault().Name);
Now, I have put test here. Which gives error like shown in image,
Now if I run code in console application, then code is working fine, code snippet is given below
dynamic item = new Item();
item.Insert(new { Name = "Maggi", Description = "Its 2 Min Nuddles", IsDelete = false });
var result = item.All();
foreach (var i in result)
{
Console.WriteLine(i.Name + i.Description);
}
Console.Read();
Here, code is working and same thing is not working with NUnit Test. Please have a look and help me out. Please let me know if any further information is needed from my side.
Most probable explanation is that you haven't set up your connection string in the test project.
If you are using NUnit, just put it in app.config of your test project.
Solved... There is a issue with NUnit Testing. It was not taking config file pefectly. So, I made two changes. Changes I have done in Project setting.
First change is to change Application Base to bin\debug just give application base as this and then config file to .config to .exe.config and things are up and running. :)