Dear QC Community,

I am having a hard time setting up QC local and cloud development to be able to share code between multiple C# projects. There is documentation about how to share code between projects: 

However, employing this method does not seem to work for me. It does not seem to work in local backtesting nor in the QC cloud. My goal is to have a way to use the same sharing technique in Visual Studio, local QC backtesting and in the QC cloud.

As an example, I create two projects “MyAlgo” and “MyCommonCode”. The goal is to share code from “MyCommonCode” in “MyAlgo”.

In order to achieve this I try the following: In my local directory, when I ran “lean init” I run:

# Create the two projects
lean create-project -l csharp MyAlgo
lean create-project -l csharp MyCommonProject

# Create solution as described in the documentation:
# https://www.quantconnect.com/docs/v2/lean-cli/tutorials/code-sharing
dotnet new sln
dotnet sln add MyAlgo
dotnet sln add MyCommonProject

With that, in Visual Studio, I have to add a reference to the project “MyCommonProject” in “MyAlgo”. Now I am able to use code, at least in Visual Studio, written in “MyCommonProject” in “MyAlgo”.

I then add some test class to “MyCommonCode” which I want to ruse in “MyAlgo”. Therefore, in “MyAlgo”, in “Main.ch” I have something like:

using MyCommonProject;

This works out fine in Visual Studio.

When running a local backtest, I get the following error:

lean backtest MyAlgo
[...]
  CsMyCommonProjectShared -> /Compile/bin/MyCommonProject.dll
  MyAlgo -> /Compile/bin/MyAlgo.dll
[...]
20220223 06:31:06.374 ERROR:: Engine.Run(): During the algorithm initialization, the following exception has occurred: Could not load file or assembly 'MyCommonProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The 
system cannot find the file specified.
 in BacktestingSetupHandler.cs:line 186 Could not load file or assembly 'MyCommonProject, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

 

When uploading the project to QC cloud I am not even able to build “MyAlgo” as it does not seem to know about the reference to "MyCommonProject".

 16 | 01:38:48: 
Build Error: File: Main.cs Line:2 Column:6 - The type or namespace name 'MyCommonProject' could not be found (are you missing a using directive or an assembly reference?)

 

What is the right (and elegant) way to achieve this?

 

 

Author