Get TFS version programmatically - tfs

How can I get the TFS version programmatically?
I am trying to get the version that shows up in the TFS Administration console.
I tried the following code, but it returns the server version as "Server Version: Dev14.M89-Part7", that doesn't seem correct.
var server = new TfsTeamProjectCollection(new Uri("http://tfs2015:8080/tfs"));
server.EnsureAuthenticated();
var serverVersion = server.ServerDataProvider.ServerVersion;
Console.WriteLine("Server Version: {0}", serverVersion);
I guess I am looking at the wrong property...

I'm using the Microsoft.TeamFoundation.Server.dll version number then the table from this link.

Unfortunately there is not some uniform method that you can call that will simply tell you “You are communicating with version X of TFS”. In order to determine what version of the server you are talking to we are going to use the principals about querying for services along with some knowledge about what services were available in each release.
Check this blog:http://blogs.msdn.com/b/taylaf/archive/2010/01/05/determining-the-tfs-server-version-using-client-apis.aspx

Another approach can be to pick the version number from a DLL, but requires to reach the server via PSExec, CIFS/SMB or Powershell Remoting.
The C# code should be something like
using (var tfsBaseKey = Registry.LocalMachine.OpenSubKey(#"SOFTWARE\Microsoft\TeamFoundationServer"))
{
var versionKeys = tfsBaseKey.GetSubKeyNames();
double dummy;
double maxVersion = versionKeys.Max(x => double.TryParse(x, out dummy) ? dummy : 0.0);
var latestVersionKey = maxVersion.ToString("#.0");
using (var tfsKey = tfsBaseKey.OpenSubKey(latestVersionKey))
{
string tfsInstallPath = tfsKey.GetValue("InstallPath").ToString();
string refAssemblyPath = Path.Combine(tfsInstallPath, #"Application Tier\Web Services\bin\Microsoft.TeamFoundation.Server.Core.dll");
var refAssembly = Assembly.ReflectionOnlyLoadFrom(refAssemblyPath);
var fileVer = refAssembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false).FirstOrDefault() as AssemblyFileVersionAttribute;
return fileVersion.Version;
}
}

Related

Can I auto-increment the CFBundleVersion value in the Info.plist file using Visual Studio?

I've seen solutions to doing this with Xcode and even Xamarin Studio, but nothing with Visual Studio.
Ideally, I'd like for every single build of the project to auto-increment the CFBundleVersion value within the Info.plist file.
<key>CFBundleVersion</key>
<string>9</string>
I don't even know where to start and haven't been able to find an article / blog post / tutorial on anything that includes Visual Studio.
Is this possible?
Just wanted to add that I am using Visual Studio 2015 on Windows 8.1.
Being in the same boat as you, as in not finding a proper solution, I decided to create my own. Maybe better late than never! :)
In my case I used the very useful Automatic Versions Settings tool (available on NuGet) to automatically update my assembly info, but wanted that to also update the Info.plist information as that's what HockeyApp uses to track and notify of new releases.
In the end, I kludged together a minimal C# program, which reads AssemblyInfo.cs, grabs the version info from there and edits the Info.plist XML file and writes it back.
It'd be a 20 line program if I hadn't put in a lot of paranoid checks, so as not to risk mangling Info.plist irretrievably (and even then it creates a backup of that file).
The "magic" comes down to two methods, the first one which I found here on SO:
Read AssemblyInfo.cs:
private static string GetVersionFromAssemblyInfo(string infile)
{
var version = String.Empty;
var readText = File.ReadAllLines(infile);
var versionInfoLines = readText.Where(t => t.Contains("[assembly: AssemblyVersion"));
foreach (var item in versionInfoLines)
{
version = item.Substring(item.IndexOf('(') + 2, item.LastIndexOf(')') - item.IndexOf('(') - 3);
}
return version;
}
Edit Info.plist, where the first 3 elements of the assembly info tuple becomes the CFBundleShortVersionString and the last element becomes CFBundleVersion which HockeyApp uses for build number.
The wonkiness in the LINQ is due to the slight weirdness of Apple's way of presenting the key/value pairs in that file:
private static bool SetVersionInInfoPlist(string infoplistFile, string version, string number)
{
var xelements = XDocument.Load(infoplistFile);
var dict = from el in xelements.Root?.Elements() select el;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (dict == null) return false;
var cfshortversion =
from el in dict.Descendants("key")
where el.Value == "CFBundleShortVersionString"
select el.ElementsAfterSelf().FirstOrDefault();
;
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (cfshortversion == null) return false;
cfshortversion.FirstOrDefault()?.SetValue(version);
var cfversion =
from el in dict.Descendants("key")
where el.Value == "CFBundleVersion"
select el.ElementsAfterSelf().FirstOrDefault();
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (cfversion == null) return false;
cfversion.FirstOrDefault()?.SetValue(number);
// Make backup
try
{
File.Copy(infoplistFile, $"{infoplistFile}-backup", true);
}
catch (Exception)
{
Console.WriteLine($"Failed to create backup of {infoplistFile}. Will not edit.");
return false;
}
try
{
using (StringWriter sw = new StringWriter())
{
using (XmlWriter xWrite = XmlWriter.Create(sw))
{
xelements.Save(xWrite);
}
}
xelements.Save(infoplistFile);
}
catch (Exception)
{
Console.WriteLine($"Failed to save the edited {infoplistFile}.");
return false;
}
Console.WriteLine($"Successfully edited and saved new {infoplistFile}.");
return true;
}
EDIT: I should have also added that I use Bamboo for CI and build automation. This program therefore becomes a capability for the remote build agent and then I can add it as a Task in the Bamboo build Plan.

How to Communiccate between JD Edwards Enterprise one 9.0 and .Net

I have problem that how to communicate Jd Edwards Enterprise one 9.0 with .Net,and my project manager told me to look at the "fatclient" as it acts as a middle ware between these two,but there is no luck in my search,
Thanks in advance
Responding to this old post. Hopefully, this will help someone who has a similar need:
Take a look at our product LynX Business Integrator. It is Oracle Validated and it allows you to create integration processes natively in C# and publish it as a web service. So, you can write code like this:
private bool CallAddressBookBsfn(BusinessDocument businessDocument, Transaction transaction)
{
AddressBookMaster abm = businessDocument.document.input.AddressBook;
// create an instance of the Address Book Master Business function
// note the use of JDE Transactions
AddressBookMasterMBF bsfn = new AddressBookMasterMBF(transaction);
// set parameters - most of this code is auto-generated
bsfn.DpmnAddressBookNumber.InValue = (long)abm.AddressNumber;
bsfn.DpszSearchType.InValue = abm.AddressType;
bsfn.DpszAlphaName.InValue = abm.Name;
bsfn.DpszAddressLine1.InValue = abm.AddressLine1;
bsfn.DpszAddressLine2.InValue = abm.AddressLine2;
bsfn.DpszAddressLine3.InValue = abm.AddressLine3;
bsfn.DpszAddressLine4.InValue = abm.AddressLine4;
bsfn.DpszPostalCode.InValue = abm.ZipCodePostal;
bsfn.DpszCity.InValue = abm.City;
bsfn.DpszState.InValue = abm.State;
bsfn.DpszCountry.InValue = abm.Country;
bsfn.DpcActionCode.InValue = 'A';
bsfn.DpcUpdateMasterFile.InValue = '1';
// execute the business function
if (bsfn.Execute() != BusinessFunctionResult.Success)
{
// get errors
return false;
}
// assign output
businessDocument.document.output.AddressNumber = bsfn.DpmnAddressBookNumber.OutValue;
businessDocument.document.output.AddressNumberSpecified = true;
return true;
}
Take a look at our YouTube Channel at http://www.youtube.com/user/aelliuslynx and our product page at http://www.aellius.com/products/lynx-business-integrator
I am using old version 8.0 and if by "communication" you mean to be able from a .NET application to run JDE BSFN directly, then i am gonna dissapoint you but there isn't any way i know of.
Maybe things have changed in 9.0 but i doubt it.
Personally whenever i want to communicate with our JDE (AS400 based) i am using:
Frontend
-.NET Web Api services
-C# winforms apps
-ASP.NET
Backend
-Custom Dlls for Business logic and Data Access Layers.

Is it possible to use the HttpClient class in MonoDroid?

I'm trying to use the HttpClient class on a MonoDroid project but it looks like the System.Net.http namespace it's not valid.
I try to add a reference in the project to System.Net.http.dll but it doesn't seem to be available in the references list.
Any idea?
Thks
HttpClient is a .NET 4.5 class, which is not available yet in Mono for Android. Mono itself added supported for it in version 3.0, but Mono for Android is still based on Mono 2.10. I know Xamarin is working on updating Mono for Android (and MonoTouch) to Mono 3.0 now, but as far as I know there's no release date set yet.
I know it is an old thread but I just saw that Xamarin has finally given System.Net.Http in Xamarin.Android 4.8, so thought to share it with you too.
Thanks.
You can't use HttpClient (yet!), but you can still use the System.Net.HttpWebRequest object, which does actually do what HttpClient can provide convenient wrappers for (especially when hitting up a Web API controller).
Here's a sample from a current project I'm working on (it's using the monodroid port of NewtonSoft.Json, not the standard System.Runtime.Serialization.Json) :
private void AddARecord()
{
var cartesian = new Cartesian()
{
Description = "next item blah",
X = 5,
Y = 10,
Z = 15,
};
string json = JsonConvert.SerializeObject(cartesian);
var request = new HttpWebRequest(new Uri(_url)) {ContentType = "application/json", Method = "POST"};
var sw = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
sw.Write(json);
sw.Close();
request.BeginGetResponse(ProcessJsonResponseForSingleResult, request);
}
...the Web API controller I'm hitting does something arbitrary, saves the object I just sent, and then tweaks the description so I know it works. Then it sends the tweaked object back...
And then the callback ProcessJsonResponseForSingleResult looks like
private void ProcessJsonResponseForSingleResult(IAsyncResult ar)
{
var request = (HttpWebRequest)ar.AsyncState;
var response = request.EndGetResponse(ar);
using (var outputStream = new StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII))
{
var jsonString = outputStream.ReadToEnd();
Log.Info("PJRFSR", string.Format("JSON string: {0} - deserialising...", jsonString));
var cartesian = JsonConvert.DeserializeObject<Cartesian>(jsonString);
RunOnUiThread(() => UpdateUiTextView(cartesian.Description));
}
}
Yeah, I know, it uses the BeginAsync/EndAsync pattern which I don't like any more either, but it does work if you just need to get something done.

Programming TFS: How to find out if a particular file exists on the server?

How can I programatically find out if a particular file exists on TFS server?
You can do it by using the ServerItemExists() method on an instance of a VersionControlServer.
using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(
new Uri("http://tfs:8080/tfs/DefaultCollection")))
{
var server = tfs.GetService<VersionControlServer>();
Boolean doesFileExist = server.ServerItemExists("$/Project/Main/MySoltuion.sln", ItemType.File);
}
Found the answer myself:
ServerItemExists method
http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.versioncontrolserver.serveritemexists(v=vs.100).aspx
http://social.msdn.microsoft.com/Forums/pl-PL/vsx/thread/306753e5-8dc4-4f56-9748-9082db3f0c24

Is there a relatively easy way for a hybrid .Net exe (console app/Windows service) to install and start itself as a service?

Suppose an executable named ConsoleOrService.exe is written in C#. It currently is a hybrid. I can just start it on the command line, or I can install it using the .Net's installutil ConsoleOrService.exe and then start the service. I would like a third option: running it on the command line like so: ConsoleOrService.exe --install and have it do all of the work.
Is this possible?
Is this hard?
How can I get started?
Thank you, and let me know if there are questions please.
It's actually quite simple. I've used it in many of my own services (in fact, ALL of my services are capable of doing their own install/uninstall. I control it with a command-line switch, such as /install or /uninstall.
The installation is performed like this:
private static void InstallService()
{
var ti = new System.Configuration.Install.TransactedInstaller();
var si = new MyServiceInstaller();
var cl = new string[] { string.Format(CultureInfo.InvariantCulture, "/assemblypath={0}", System.Reflection.Assembly.GetExecutingAssembly().Location) };
var ctx = new System.Configuration.Install.InstallContext(null, cl);
ti.Installers.Add(si);
ti.Context = ctx;
ti.Install(new Hashtable());
}
The uninstallation is the same, except that you call ti.Uninstall(null); instead of ti.Install(...);.
My MyServiceInstaller is a class that inherits from the System.Configuration.Install.Installer class (as you would normally have in a service).

Resources