Skip to content

Commit

Permalink
Improve handling of net versions missmatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin-Molinero committed Dec 17, 2024
1 parent 0f8aa4f commit 8dc3e4f
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lean/components/docker/lean_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,14 @@ def set_up_csharp_options(self, project_dir: Path, run_options: Dict[str, Any],
"mode": "rw"
}

framework_ver = self._docker_manager.get_image_label(image, 'target_framework',
DEFAULT_LEAN_DOTNET_FRAMEWORK)

# Ensure all .csproj files refer to the version of LEAN in the Docker container
csproj_temp_dir = self._temp_manager.create_temporary_directory()
for path in compile_root.rglob("*.csproj"):
self._ensure_csproj_uses_correct_lean(compile_root, path, csproj_temp_dir, run_options)
self._ensure_csproj_is_valid(compile_root, path, csproj_temp_dir, run_options, framework_ver)

framework_ver = self._docker_manager.get_image_label(image, 'target_framework',
DEFAULT_LEAN_DOTNET_FRAMEWORK)
# Set up the MSBuild properties
msbuild_properties = {
"Configuration": "Release" if release else "Debug",
Expand Down Expand Up @@ -770,11 +771,12 @@ def _get_csharp_compile_root(self, project_dir: Path) -> Path:

return project_dir

def _ensure_csproj_uses_correct_lean(self,
compile_root: Path,
csproj_path: Path,
temp_dir: Path,
run_options: Dict[str, Any]) -> None:
def _ensure_csproj_is_valid(self,
compile_root: Path,
csproj_path: Path,
temp_dir: Path,
run_options: Dict[str, Any],
net_framework: str) -> None:
"""Ensures a C# project is compiled using the version of LEAN in the Docker container.
When a .csproj file refers to the NuGet version of LEAN,
Expand All @@ -791,6 +793,14 @@ def _ensure_csproj_uses_correct_lean(self,
csproj = self._xml_manager.parse(csproj_path.read_text(encoding="utf-8"))
include_added = False

if net_framework:
target_framework_iter = csproj.iter("TargetFramework")
if target_framework_iter:
target_frameworks = [framework.text for framework in target_framework_iter]
if net_framework not in target_frameworks:
raise RuntimeError(f".NET version missmatch detected, project: {target_frameworks} "
f"image: '{net_framework}'. Please update '{csproj_path}' to use '{net_framework}'")

for package_reference in csproj.iter("PackageReference"):
if not package_reference.get("Include", "").lower().startswith("quantconnect."):
continue
Expand Down

0 comments on commit 8dc3e4f

Please sign in to comment.