YouTrackSharp 3.0 beta – A .NET Standard Client for YouTrack

YouTrackSharpPlease welcome a brand new (preview) version of YouTrackSharp – a .NET library to work with the YouTrack REST API. It’s a complete rewrite from the previous version, since a lot of things in the .NET world have changed.

First of all, YouTrackSharp now targets  .NET Standard 1.3, which means it can now be used with pretty much any .NET platform, including .NET Framework 4.6, .NET Core, Mono, Xamarin, and UWP. We wanted to make sure many different applications could be developed with YouTrackSharp, on many platforms.

Another benefit of being on this new stack is we were able to make YouTrackSharp async all the way. And we were able to tackle some other things, too, like handling serialization of YouTrack’s timestamps into DateTime where possible. Let’s have a look!

Getting started

We are distributing YouTrackSharp as a NuGet package, which means it can be easily installed into a project using Visual Studio, Rider, the .NET CLI, Paket or VS Code.

Install-Package YouTrackSharp

Once that is done, we can start working with it. To communicate with a YouTrack server instance, we’ll need a connection. It is recommended to always use permanent tokens to authenticate against YouTrack, using the BearerTokenConnection class. For YouTrack instances that do not have token support, UsernamePasswordConnection can be used.

Once we have a connection instance, we can start working with various services that are available through extension methods on our connection. For example if we want to dump all issues with their id, summary and current state, we can do so through the IssuesService:

One thing to note here is that some fields are available as a direct property on the Issue, like Id and Summary, while others are available using the GetField() method. Since not all projects have the same fields, these project-specific fields are available using GetField() and SetField(). An added benefit of using the GetField() method is that it allows returning the value AsString(), AsDateTime(), AsCollection() or AsInt32(). Prefer working with dynamic? That’s fine, too, but keep in mind you’ll have to cast the correct types manually then.

One more example: creating an issue, including setting the Priority field using dynamic:

Maybe one more? What about time tracking for an issue:

Available REST API’s

YouTrackSharp provides several services we can work with:

Next to these, we have also added the various color indices available in YouTrack. We can use the ColorIndices class which maps the index to a foreground and background color, or use the (hex) colors exposed on the field directly:

What about other languages?

While YouTrackSharp focuses on the various .NET languages like C#, VB.NET and F#, there are YouTrack API wrappers for languages as well. A quick search on libraries.io shows Java and Kotlin, PHP, JavaScript, Python and Ruby.

Give the new YouTrackSharp a try, and let us know how it goes! If you feel like contributing, feel free to tackle one of the UpForGrabs issues and help make YouTrackSharp better!

About Maarten Balliauw

Maarten Balliauw is a Developer Advocate at JetBrains, working on .NET tools. He focuses on .NET, Azure, web technologies and application performance. Maarten is a frequent speaker at various national and international events. In his free time, he brews his own beer. Follow him on Twitter or check his personal blog.
This entry was posted in how-to, tips and tagged , , , , , . Bookmark the permalink.

6 Responses to YouTrackSharp 3.0 beta – A .NET Standard Client for YouTrack

  1. Robert Wright says:

    Hi Maarten,

    I’m trying to use the new version of the API v3.0.1 and I’m getting an error when trying to get the list of projects that I have access to using the below code:-

    var issuesService = connection.CreateIssuesService();
    var sprintIssues = await issuesService.GetIssuesInProject(“Everything”, null, null, 99, null, false);

    But I’m getting an error when I make the call with the await keyword :-
    “Unexpected character encountered while parsing value: <. Path '', line 0, position 0."

    I'm want to print out the issues so we can use a physical sprint board.

    I'm using Newtonsoft.Json v10.0.0.0
    .Net Framework 4.6
    Visual Studio 2017 v15.2

    Any help would be greatly appreciated.

    Cheers
    Robert

  2. David Refaeli says:

    Does the old syntax not supported anymore? I have a 4.5 .NET Framework app, and I can’t install YouTrackSharp 3.0, only 2.0.

    I try to use the old syntax:
    var connection = new Connection(“xxxx.myjetbrains.com”, 80, false, “youtrack”);
    connection.Authenticate(“xxxxx”, “xxxxxx”);

    And it tells me “Method not allowed”;

    If I try only new Connection(“xxxx.myjetbrains.com”) it throws an error:

    “For security reasons DTD is prohibited in this XML document. To enable DTD processing set the DtdProcessing property on XmlReaderSettings to Parse and pass the settings into XmlReader.Create method.”

Leave a Reply

Your email address will not be published. Required fields are marked *