Project Development Samples: ProjToolV2


Many of you will be familiar with the original ProjTool which we released as a sample for Project Server 2007 and 2010 for use of the PSI to program against Project Server.  We have just released a new ProjTool that uses CSOM and has many of the familiar options of the original tool.  This is distributed as per our other recent samples via the OfficeDev section on GitHub and can be downloaded with all the other samples from https://github.com/OfficeDev/O365-Project-Online-.Net-Samples.  Take care where you unzip these as you can end up getting warning in Visual Studio about path lengths.  The specific ProjToolV2 is in the 365-Project-Online-OM-ProjToolV2 section, and despite the name it can be run against Project Server 2013 and 2016 as well as Project Online.

To walk you through getting this up and running I’ll assume you have some version of Visual Studio already loaded (I have Visual Studio 2015 Professional) so you first download the samples (may as well get them all – you can then play with the others too!)

*** 6/8/2016 You will need to use Visual Studio 2015 or above as the sample uses a new C# feature, interpolated Strings . Thanks Steven Haden for the info ***

image

Unzip and read the license agreement (of course) then open ProjToolV2.sln.

image

If you try and build it straight off you will hit some namespaces not found errors – as you need the SharePoint Client Object Model libraries.  I happened to choose to use the ones for SharePoint Online as these are conveniently available via nuget.org.  The GitHub page also lists the Project Server 2013 ones. However, to get the SharePoint Online ones you navigate to https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/ and take a look at the link for the Package Manager Console.  I already have the console installed – so I can just enter

Install-Package Microsoft.SharePointOnline.CSOM - and hit return to get this loaded:

image

One other error – we have an .ico file referenced in the wrong location – so you will get this:

Error opening icon file D:\Tools\365-Project-Online-OM-ProjToolV2\ProjToolV2\Project.ico -- Could not find file 'D:\Tools\365-Project-Online-OM-ProjToolV2\ProjToolV2\Project.ico'

I simply copied it from the images directory to the location where it was looking – but you could reference the images directory instead.  Click Start again and my ProjToolV2 was ready to go!

image

I’ve set my Url (which, despite the name, happens to be a Project Server 2013 machine) and I can use Windows to log in.  If you want to connect to a Project Online PWA then just check the box.

image

The next screen is where you can really start doing stuff – plenty of option down the left to interact with the various Project entities, as well as being able to turn logging on so you can track what the application is doing (under Settings – top right).  First I’ll click Project under the Update section – select a project from the dropdown that gets populated and see what I can see.  I’ve navigated to the Tasks tab as there is more to see – and scrolled across a bit.

image

Filter fields is a feature from the previous ProjTool that can be very useful – if I am only interested in fields that contain ‘start’ – then I can filter away!

image

This isn’t meant to be an editing tool for projects – so we don’t suggest you point this at your production systems – but it is a great way to get started with CSOM programming with Project Server and Project Online!

Here is the Project Creation dialog – with plenty of options for choosing how your new plans are configured:

image

This is great for creating a bunch of Projects – but they tend to be pretty boring with set names and tasks etc.  But you can also have it set assignments and use either local or enterprise resources.  There are plenty of other options for resources, lookup tables and custom fields for you to try out, and of course look at the code that makes it all happen  However, the release of this was really timely as I had a need today to check out a CSOM method for creating a project from a template.  Now this isn’t one of the features present in the initial release (Robert has added to the backlog!) but one thing I’ve often used ProjTool for is a ready made harness for other stuff I need to do – without having to build from scratch.  There is a parameter you can set in your ProjectCreationInformation to set a Enterprise Project Type Id.

I could find out the EPT Id from the Url of the Enterprise Project Type – just by clicking through from the PWA Settings, Enterprise Project Types page – and here is the full string - http://brismithp16/PWA/_layouts/15/PWA/Admin/EnterpriseProjectTypeDetails.aspx?entProjectTypeUid=e60ecff8-28ed-e411-80d2-001dd8b731f9.

The code I needed to change can be found in the Creation folder – and specifically the ProjectsCreation.cs file.

image

Mine was a quick and dirty test – so I was happy to hard code in the GUID, so just needed to add the parameter after the projName.  So my new code looked like this:

string projName = txtProjName.Text + projCount;
List<EnterpriseResource> projectTeam = new List<EnterpriseResource>();
PublishedProject newProject = ProjContext.Projects.Add(new ProjectCreationInformation { Name = projName, EnterpriseProjectTypeId = new Guid("e60ecff8-28ed-e411-80d2-001dd8b731f9") });

(Careful if copying – WordPress sometimes turns quotes into ‘smart quotes’ – which isn’t very smart! – and of course use your own GUID)

This would probably get confused if you also checked the options for adding task, assignments etc. – but worked perfectly to test out creating a project from a template using CSOM.  I was also very pleased to see this work – as we recently broke the CreateProjectFromTemplate method in Project Server 2013 with the March Update (it appears to work but you never see the projects show up!).

Have fun with ProjToolV2 – take a look at the code and use this as an easy path into Github, Nuget and CSOM if, like me, these are all pretty new concepts for you.


Comments (13)

  1. Jemma says:

    Hi,

    Is there a way for me to compile this as a program and send to my colleagues, who do not have Visual Studio?

    Regards,
    Jemma

    1. Hi Jemma, when you build the application the exe created in the \bin\debug (ProjToolV2.exe) could be shared with your colleagues – which would also need the following DLL’s copied over too:

      Microsoft.ProjectServer.Client.dll
      Microsoft.SharePoint.Client.dll
      Microsoft.SharePoint.Client.Runtime.dll

      These can be found in the packages\Microsoft.SharePointOnline.CSOM.16.1.5026.1200\lib\net45 folder of the solution (assumes the nuget package at the time of writing). So just having those 4 files in the same folder should allow your colleagues without Visual Studio to use the application.

      Best regards,
      Brian

  2. Jim Black CG says:

    Hi Brian,
    Thanks for the great content. This is the sort of thing I’ve been hoping to see from Microsoft Tech Support! As you continue your creation of content like this, I would hope that you can publish some information on how to use LINQ queries to extract Task and Resource data from Project Server via CSOM. Good examples of using LINQ queries to select only certain tasks and only certain fields from those tasks would be very helpful. Many of us are finding that the detailed information available for SharePoint client queries via LINQ does not do justice to the Microsoft Project Server data model.

    Jim

  3. Mike Peterson says:

    Hi Brian, This is great. This doesn’t, however, include anything on Resource Engagements. Can you point me to any sample code for this?

    1. Thanks Mike and Jim – I don’t have any suitable samples yet – but I’ll feed back to the team the need for these.

      1. Mike Peterson says:

        Thanks Brian. Is Resource Engagements functionality available via CSOM for Project Online or 2016 OnPrem? I don’t see any public interfaces for them.

        1. Coming very soon Mike – I’ll see if I can get an update from the product group.
          Best regards,
          Brian

  4. Johannes Uhlig says:

    I found that compile in Windows 10 crashes with System.DirectoryServices.AccountManagement.dll FileNotFoundException. The following fix worked for me:

    http://stackoverflow.com/questions/33717673/system-directoryservices-accountmanagement-principalcontext-broken-after-windows

  5. Roy Gilboa says:

    Hi Brian,
    Question I asked on another post of yours but may be more relevant here:

    The Engagements CSOM API works well for Project Online but fails when attempteing the exact same code on 16 On Premise (minus the authentication off course).
    The error seems to be coming from the server:
    “Microsoft.SharePoint.Client.ServerException: Field or property “Engagements” does not exist.
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
    at TestEngagementsAPI.ReadEngagements()”.

    Is this a known issue?
    Thanks

    1. Hi Roy, the Resource Engagements methods are not available in Project Server 2016 – only Project Online. It would be worth opening a support incident to make you requirements know – or go to UserVoice – https://microsoftproject.uservoice.com/forums/218133-microsoft-project. The product group need to hear of the requirement so they will prioritize the work to add this capability.
      Thanks and best regards,
      Brian.

      1. Roy Gilboa says:

        Thanks Brian

  6. Syed says:

    Excellent!! great content, Brian

  7. Amr Ammar says:

    Good Job
    but I tried the updated version of Microsoft.SharePointOnline.CSOM 16.1.6906.1200 and always I get a n exception while logging in
    the application works correctly with version Microsoft.SharePointOnline.CSOM 16.1.5626.1200

Skip to main content