Project Development Samples: ProjToolV2
Published Mar 06 2019 02:11 PM 1,046 Views
Brass Contributor

First published on MSDN on Apr 26, 2016
*** Update 7/23/21

 

If you are trying to use the ProjTool for Project Online then you will need to set the target framework to 4.7.2 and also edit the following line in csomhelper.cs due to a change in the object properties.

// string currentUserName = UserPrincipal.Current.DisplayName;
string currentUserName = Settings.Default.UserName; 

***

 

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 ***



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



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:




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!



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.



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.



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!



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:



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=e6... .

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



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.

Co-Authors
Version history
Last update:
‎Jul 23 2021 10:02 AM
Updated by: