-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDotNETCLIClient.py
114 lines (100 loc) · 4.03 KB
/
DotNETCLIClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import subprocess
import os
class DotNETCLIClient:
def __init__(self):
self.verify_dotnet_installed()
def verify_dotnet_installed(self):
"""Verify that .NET SDK is installed"""
try:
subprocess.run(['dotnet', '--version'], check=True, capture_output=True)
except subprocess.CalledProcessError:
raise RuntimeError(".NET SDK is not installed or not in PATH")
def new_project(self, template, output_dir=None, name=None):
"""
Create a new .NET project
Args:
template (str): The template to use (e.g., 'console', 'classlib', 'web')
output_dir (str, optional): Output directory for the project
name (str, optional): Name of the project
"""
command = ['dotnet', 'new', template]
if output_dir:
command.extend(['-o', output_dir])
if name:
command.extend(['-n', name])
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Project created successfully: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Error creating project: {e.stderr}")
return False
def build(self, project_path=None):
"""Build the .NET project"""
command = ['dotnet', 'build']
if project_path:
command.append(project_path)
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Build successful: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Build failed: {e.stderr}")
return False
def run(self, project_path=None):
"""Run the .NET project"""
command = ['dotnet', 'run']
if project_path:
command.extend(['--project', project_path])
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Run output: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Run failed: {e.stderr}")
return False
def new_solution(self, name=None):
"""
Create a new solution file
Args:
name (str, optional): Name of the solution
"""
command = ['dotnet', 'new', 'sln']
if name:
command.extend(['-n', name])
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Solution created successfully: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Error creating solution: {e.stderr}")
return False
def add_project_to_solution(self, sln_path, project_path):
"""
Add a project to a solution
Args:
sln_path (str): Path to the solution file
project_path (str): Path to the project file
"""
command = ['dotnet', 'sln', sln_path, 'add', project_path]
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Project added to solution successfully: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Error adding project to solution: {e.stderr}")
return False
def new_gitignore(self):
"""
Create a new .gitignore file using the dotnet CLI
Returns:
bool: True if successful, False otherwise
"""
command = ['dotnet', 'new', 'gitignore']
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
print(f"Gitignore created successfully: {result.stdout}")
return True
except subprocess.CalledProcessError as e:
print(f"Error creating gitignore: {e.stderr}")
return False