Class: Makit::DotNet::SolutionWpf

Inherits:
Object
  • Object
show all
Defined in:
lib/makit/dotnet/solution_wpf.rb

Class Method Summary collapse

Class Method Details

.generate_gitlab_ci(project_name) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/makit/dotnet/solution_wpf.rb', line 146

def self.generate_gitlab_ci(project_name)
  gitlab_ci_content = "    # \#{project_name} WPF Project GitLab CI/CD Pipeline\n    # frozen_string_literal: true\n\n    stages:\n      - build\n      - test\n      - publish\n\n    variables:\n      DOTNET_VERSION: \"8.0.x\"\n      PROJECT_PATH: \"source/\#{project_name}/\#{project_name}.csproj\"\n      BUILD_CONFIGURATION: \"Release\"\n      TEST_RESULTS_DIR: \"test-results\"\n      COVERAGE_DIR: \"coverage\"\n      PUBLISH_DIR: \"artifacts/publish\"\n\n    # Cache NuGet packages between jobs\n    cache:\n      paths:\n        - \"**/bin/\"\n        - \"**/obj/\"\n        - \"**/packages/\"\n        - \"~/.nuget/packages/\"\n\n    # Build job (Windows only)\n    build:\n      stage: build\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      script:\n        - echo \"Building \#{project_name} WPF project...\"\n        - dotnet --version\n        - dotnet restore $PROJECT_PATH\n        - dotnet build $PROJECT_PATH --configuration $BUILD_CONFIGURATION --no-restore\n        - echo \"WPF project build completed successfully!\"\n      artifacts:\n        paths:\n          - \"**/bin/\"\n          - \"**/obj/\"\n        expire_in: 1 week\n        when: on_success\n      rules:\n        - if: $CI_PIPELINE_SOURCE == \"merge_request_event\"\n        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n        - if: $CI_COMMIT_TAG\n\n    # Test job (Windows only)\n    test:\n      stage: test\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      dependencies:\n        - build\n      script:\n        - echo \"Testing \#{project_name} WPF project...\"\n        - dotnet test $PROJECT_PATH --configuration $BUILD_CONFIGURATION --no-build --verbosity normal\n        - echo \"WPF project tests completed successfully!\"\n      artifacts:\n        paths:\n          - $TEST_RESULTS_DIR/\n          - $COVERAGE_DIR/\n        reports:\n          junit: $TEST_RESULTS_DIR/*.xml\n        expire_in: 1 week\n        when: always\n      rules:\n        - if: $CI_PIPELINE_SOURCE == \"merge_request_event\"\n        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n        - if: $CI_COMMIT_TAG\n\n    # Publish job (Windows only)\n    publish:\n      stage: publish\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      dependencies:\n        - test\n      script:\n        - echo \"Publishing \#{project_name} WPF project...\"\n        - mkdir -p $PUBLISH_DIR\n        - dotnet publish $PROJECT_PATH --configuration $BUILD_CONFIGURATION --output $PUBLISH_DIR/\#{project_name}\n        - echo \"WPF project publish completed successfully!\"\n      artifacts:\n        paths:\n          - $PUBLISH_DIR/\n        expire_in: 1 month\n        when: on_success\n      rules:\n        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n        - if: $CI_COMMIT_TAG\n\n    # Self-contained publish job (Windows only)\n    publish_self_contained:\n      stage: publish\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      dependencies:\n        - test\n      script:\n        - echo \"Creating self-contained deployment for \#{project_name}...\"\n        - mkdir -p $PUBLISH_DIR\n        - dotnet publish $PROJECT_PATH --configuration $BUILD_CONFIGURATION --runtime win-x64 --self-contained true --output $PUBLISH_DIR/\#{project_name}-self-contained\n        - echo \"Self-contained deployment completed successfully!\"\n      artifacts:\n        paths:\n          - $PUBLISH_DIR/\n        expire_in: 1 month\n        when: on_success\n      rules:\n        - if: $CI_COMMIT_TAG\n\n    # Code quality job (Windows only)\n    code_quality:\n      stage: test\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      dependencies:\n        - build\n      script:\n        - echo \"Running code quality checks...\"\n        - dotnet tool install --global dotnet-format\n        - dotnet format --verify-no-changes $PROJECT_PATH\n        - echo \"Code quality checks completed!\"\n      allow_failure: true\n      rules:\n        - if: $CI_PIPELINE_SOURCE == \"merge_request_event\"\n        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n\n    # Security scan job (Windows only)\n    security_scan:\n      stage: test\n      image: mcr.microsoft.com/dotnet/sdk:8.0\n      tags:\n        - windows\n      dependencies:\n        - build\n      script:\n        - echo \"Running security scan...\"\n        - dotnet tool install --global dotnet-outdated-tool\n        - dotnet outdated $PROJECT_PATH\n        - echo \"Security scan completed!\"\n      allow_failure: true\n      rules:\n        - if: $CI_PIPELINE_SOURCE == \"merge_request_event\"\n        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH\n  YAML\n\n  File.write(\".gitlab-ci.yml\", gitlab_ci_content)\nend\n"

.generate_rakefile(project_name) ⇒ Object



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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/makit/dotnet/solution_wpf.rb', line 21

def self.generate_rakefile(project_name)
  rakefile_content = "    # frozen_string_literal: true\n\n    require \"makit\"\n\n    #\n    # \#{project_name} WPF Project Rakefile\n    #\n    desc \"default task - builds and tests the WPF project\"\n    task :default => [:build, :test]\n\n    desc \"build the \#{project_name} WPF project\"\n    task :build do\n      puts \"Building \#{project_name} WPF project...\"\n      project_path = \"source/\#{project_name}/\#{project_name}.csproj\"\n    \#{\"  \"}\n      if File.exist?(project_path)\n        sh \"dotnet build \\\#{project_path} --configuration Release\"\n        puts \"WPF project build completed successfully!\"\n      else\n        puts \"Error: Project file not found at \\\#{project_path}\"\n        exit 1\n      end\n    end\n\n    desc \"test the \#{project_name} WPF project\"\n    task :test do\n      puts \"Testing \#{project_name} WPF project...\"\n      project_path = \"source/\#{project_name}/\#{project_name}.csproj\"\n    \#{\"  \"}\n      if File.exist?(project_path)\n        sh \"dotnet test \\\#{project_path} --configuration Release --verbosity normal\"\n        puts \"WPF project tests completed successfully!\"\n      else\n        puts \"Error: Project file not found at \\\#{project_path}\"\n        exit 1\n      end\n    end\n\n    desc \"run the \#{project_name} WPF project\"\n    task :run => [:build] do\n      puts \"Running \#{project_name} WPF project...\"\n      project_path = \"source/\#{project_name}/\#{project_name}.csproj\"\n    \#{\"  \"}\n      if File.exist?(project_path)\n        sh \"dotnet run --project \\\#{project_path} --configuration Debug\"\n      else\n        puts \"Error: Project file not found at \\\#{project_path}\"\n        exit 1\n      end\n    end\n\n    desc \"clean build artifacts\"\n    task :clean do\n      puts \"Cleaning WPF project build artifacts...\"\n      sh \"dotnet clean source/\#{project_name}/\#{project_name}.csproj\"\n      puts \"Clean completed successfully!\"\n    end\n\n    desc \"restore packages\"\n    task :restore do\n      puts \"Restoring WPF project packages...\"\n      sh \"dotnet restore source/\#{project_name}/\#{project_name}.csproj\"\n      puts \"Restore completed successfully!\"\n    end\n\n    desc \"publish the WPF project\"\n    task :publish do\n      puts \"Publishing \#{project_name} WPF project...\"\n      output_dir = \"artifacts/publish/\#{project_name}\"\n      FileUtils.mkdir_p(output_dir)\n      sh \"dotnet publish source/\#{project_name}/\#{project_name}.csproj --configuration Release --output \\\#{output_dir}\"\n      puts \"WPF project publish completed successfully! Output: \\\#{output_dir}\"\n    end\n\n    desc \"create Windows installer using WiX\"\n    task :create_installer => [:publish] do\n      puts \"Creating Windows installer for \#{project_name}...\"\n      output_dir = \"artifacts/publish/\#{project_name}\"\n      installer_dir = \"artifacts/installer\"\n      FileUtils.mkdir_p(installer_dir)\n    \#{\"  \"}\n      if Dir.exist?(output_dir)\n        # Create a simple batch installer script\n        installer_script = <<~BAT\n          @echo off\n          echo Installing \#{project_name}...\n          echo.\n          echo Copying files to Program Files...\n          xcopy /E /I /Y \"\#{output_dir}\" \"C:\\\\Program Files\\\\\#{project_name}\"\n          echo.\n          echo Creating desktop shortcut...\n          echo [InternetShortcut] > \"%USERPROFILE%\\\\Desktop\\\\\#{project_name}.url\"\n          echo URL=file:///C:/Program Files/\#{project_name}/\#{project_name}.exe >> \"%USERPROFILE%\\\\Desktop\\\\\#{project_name}.url\"\n          echo.\n          echo Installation completed successfully!\n          pause\n        BAT\n    \#{\"    \"}\n        File.write(File.join(installer_dir, \"install_\#{project_name}.bat\"), installer_script)\n        puts \"Installer script created at \\\#{installer_dir}/install_\#{project_name}.bat\"\n      else\n        puts \"Error: Published output directory not found at \\\#{output_dir}\"\n        exit 1\n      end\n    end\n\n    desc \"create self-contained deployment\"\n    task :publish_self_contained do\n      puts \"Creating self-contained deployment for \#{project_name}...\"\n      output_dir = \"artifacts/publish/\#{project_name}-self-contained\"\n      FileUtils.mkdir_p(output_dir)\n    \#{\"  \"}\n      # Publish for Windows x64\n      puts \"Publishing for Windows x64...\"\n      sh \"dotnet publish source/\#{project_name}/\#{project_name}.csproj --configuration Release --runtime win-x64 --self-contained true --output \\\#{output_dir}/win-x64\"\n    \#{\"  \"}\n      puts \"Self-contained deployment completed successfully! Output: \\\#{output_dir}\"\n    end\n  RUBY\n\n  File.write(\"Rakefile\", rakefile_content)\nend\n"

.setup(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/makit/dotnet/solution_wpf.rb', line 6

def self.setup(name)
  # Check if running on Windows

  unless RUBY_PLATFORM.include?("mswin") || RUBY_PLATFORM.include?("mingw")
    raise "WPF projects can only be created on Windows platforms"
  end

  Makit::DotNet::Project.new_project("wpf", name, "source/#{name}", "--framework net8.0-windows")
  Makit::DotNet::Project.new_project("TUnit", "#{name}.Tests", "tests/#{name}")
  Makit::DotNet::Project.add_reference("tests/#{name}/#{name}.Tests.csproj", "source/#{name}/#{name}.csproj")

  # Generate additional project files

  generate_rakefile(name)
  generate_gitlab_ci(name)
end