Thursday, May 23, 2019

Adding C# project reference to D365 Project and move it to VSTS

Hello Guys, 

I would like to share with you all, how to add C# Project to our D365FO solution file (*.sln) and how to reference the same to D365FO project to make use of C# project class libraries. Then how to take these references between environments when we use VSTS. I have followed standard article to start with but failed with below error while building package in Build server.
Ideally when we add C# project reference then it will work perfectly in our Dev box but when we check-in this changes and then build in build server, it fails with below error.
Error : Error: dynamics://Class/JP_XXXXXXXXX_Extension/Method/attachFile(56,25) - The name 'JP_XXXXXXXXX_XXXXHelperLocal' does not denote a class, a table, or an extended data type.

Error : Error: dynamics://Class/ JP_XXXXXXXXX_Extension/Method/attachFile(56,96) - Class 'JP_XXXXXXXXX_XXXXHelperLocal' was not found. Are you missing a module reference? 
Compiling Compiling JPXXXModel failed  

We get this error because C# project references not moved to VSTS while check-in

Resolution:
Please follow below steps to overcome this issue.
1.     First thing is you will create your C# class library project in AX solution where you would like use.

2.     Right-click the AX project, click Add, and then click Reference. Select the row for the C# Project in the Projects references tab, and then click OK.




3.     Under the AX project, expand the References node, and there you see new reference to the project

4.     Once you have a reference then AxReference element is added to your model and the assembly (dll) is automatically copied to the bin folder of your package

File location:- 
K:\AosService\PackagesLocalDirectory\<Model Name>\<Model Name>\AxReference

File Location:- 
K:\AosService\PackagesLocalDirectory\<Model Name>\bin

If we just do these steps then it works perfectly in our Dev box(Development server) but If you are using version control, make sure to check-in both files in following location to VSTS, hence in it will compile in build server without any errors.

K:\AosService\PackagesLocalDirectory\<Model Name>\bin\ C#assembly.dll
K:\AosService\PackagesLocalDirectory\<Model Name>\<ModelName>\AxReference\C#assembly.xml

By default this dlls will not be part of version control. hence please add the same.

1.     Go to Dev branch you connected and right click on the mode you are working and click on “Add items to folder”.
2.     Then go to respective locations add those files to VSTS and now you can see those two files added to your pending changes.

3.     When you check these changes then it will be part of VSTS and when you create a deployable package for UAT or TEST on a dev/build VM that has these 2 files (AxReference and assembly files) in the desired location, the deployable package will automatically contain the needed AxReference and assembly files.

Hope this helps and will come up with another interesting blog
Happy daxing :)