Skip to content

Commit 1c81c86

Browse files
author
Beernaert Robbe
committed
updated dotnetsdk to now accept version localy and removed global.json file generation
1 parent 511df68 commit 1c81c86

File tree

3 files changed

+110
-46
lines changed

3 files changed

+110
-46
lines changed

modules/vstudio/_preload.lua

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,37 @@
298298
name = "dotnetsdk",
299299
scope = "project",
300300
kind = "string",
301-
allowed = {
302-
"Default",
303-
"Web",
304-
"Razor",
305-
"Worker",
306-
"Blazor",
307-
"WindowsDesktop",
308-
"MSTest"
309-
}
301+
allowed = function (value)
302+
-- value is expected to be in the format <sdk>/<version>
303+
local parts = value:explode("/", true, 1)
304+
local sdk = parts[1] or value
305+
local allowedSdks = {
306+
"Default",
307+
"Web",
308+
"Razor",
309+
"Worker",
310+
"Blazor",
311+
"WindowsDesktop",
312+
"MSTest"
313+
}
314+
-- Only perform the check when a version is provided to avoid infinite recursing.
315+
-- Check that the specified sdk is in the allowed list
316+
for _, allowed in ipairs(allowedSdks) do
317+
if sdk == allowed then
318+
return value
319+
end
320+
end
321+
322+
-- The specified sdk is not recognized
323+
if parts and #parts == 2 then
324+
if sdk and sdk:match("^[%w%-]+$") then
325+
return value
326+
end
327+
end
328+
329+
return nil
330+
end
331+
310332
}
311333

312334
--

modules/vstudio/tests/cs2005/test_dotnetsdk.lua

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
function suite.testDefault()
5151
prepare()
5252
setConfig()
53-
dotnetsdk "Web"
53+
dotnetsdk "Default"
5454
test.capture [[
5555
<Project Sdk="Microsoft.NET.Sdk">
5656
]]
@@ -108,11 +108,11 @@
108108

109109
function suite.testMSTest()
110110
prepare()
111-
dotnetsdk "MSTest"
111+
dotnetsdk "MSTest/3.4.0"
112112
setConfig()
113113

114114
test.capture [[
115-
<Project Sdk="MSTest.Sdk">
115+
<Project Sdk="MSTest.Sdk/3.4.0">
116116
]]
117117
end
118118

@@ -127,19 +127,62 @@
127127
]]
128128
end
129129

130-
function suite.testMSTestGlobalJSON()
130+
function suite.testWebVersion()
131131
prepare()
132-
local cfg = test.getconfig(prj, "Debug")
133-
prj.dotnetsdk = "MSTest"
134-
dn2005.output_global_json(prj)
135-
test.capture[[{"msbuild-sdks":{"MSTest.Sdk": "3.6.1"}}]]
132+
dotnetsdk "Web/3.4.0"
133+
setConfig()
134+
135+
test.capture [[
136+
<Project Sdk="Microsoft.NET.Sdk.Web/3.4.0">
137+
]]
136138
end
137139

138-
function suite.testMSTestGlobalJSONExists()
140+
function suite.testRazorVersion()
139141
prepare()
140-
local cfg = test.getconfig(prj, "Debug")
141-
prj.dotnetsdk = "MSTest"
142-
p.generate(prj, path.join(prj.workspace.location, "global.json"), function() p.outln('{"test":"global"') end)
143-
dn2005.output_global_json(prj)
144-
test.capture[[{"test":"global","msbuild-sdks":{"MSTest.Sdk": "3.6.1"}}]]
142+
dotnetsdk "Razor/3.4.0"
143+
setConfig()
144+
145+
test.capture [[
146+
<Project Sdk="Microsoft.NET.Sdk.Razor/3.4.0">
147+
]]
148+
end
149+
150+
function suite.testWorkerVersion()
151+
prepare()
152+
dotnetsdk "Worker/3.4.0"
153+
setConfig()
154+
155+
test.capture [[
156+
<Project Sdk="Microsoft.NET.Sdk.Worker/3.4.0">
157+
]]
158+
end
159+
160+
function suite.testBlazorVersion()
161+
prepare()
162+
dotnetsdk "Blazor/3.4.0"
163+
setConfig()
164+
165+
test.capture [[
166+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly/3.4.0">
167+
]]
168+
end
169+
170+
function suite.testWindowsDesktopVersion()
171+
prepare()
172+
dotnetsdk "WindowsDesktop/3.4.0"
173+
setConfig()
174+
175+
test.capture [[
176+
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop/3.4.0">
177+
]]
178+
end
179+
180+
function suite.testCustomSDKVersion()
181+
prepare()
182+
dotnetsdk "CustomSdk/3.4.0"
183+
setConfig()
184+
185+
test.capture [[
186+
<Project Sdk="CustomSdk/3.4.0">
187+
]]
145188
end

modules/vstudio/vs2005_dotnetbase.lua

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -826,36 +826,35 @@
826826
["WindowsDesktop"] = "Microsoft.NET.Sdk.WindowsDesktop",
827827
["MSTest"] = "MSTest.Sdk",
828828
}
829+
local parts = nil
830+
if cfg.dotnetsdk then
831+
parts = cfg.dotnetsdk:explode("/", true, 1)
832+
end
829833

830-
if cfg.flags.WPF then
831-
return map["WindowsDesktop"]
832-
end
834+
local sdk = (parts and #parts > 0 and parts[1]) or cfg.dotnetsdk
835+
if not parts or #parts < 2 then
836+
-- prioritize WPF flag for compatibility
837+
if cfg.flags.WPF then
838+
return map["WindowsDesktop"]
839+
end
833840

834-
return map[cfg.dotnetsdk or "Default"]
835-
end
841+
if sdk == "MSTest" then
842+
-- If sdk is MSTest, we need exactly 2 parts
843+
p.error("MSTest requires a version to be specified!")
844+
return nil
845+
end
846+
847+
return map[sdk or "Default"]
836848

837-
function dotnetbase.netcore.dotnetsdk(cfg)
838-
dotnetbase.generate_global_json(cfg)
849+
elseif parts and #parts == 2 then
850+
return string.format("%s/%s",map[parts[1]] or parts[1],parts[2])
851+
end
852+
853+
return map["Default"]
839854
end
840855

841856
function dotnetbase.allowUnsafeBlocks(cfg)
842857
if cfg.clr == "Unsafe" then
843858
_p(2,'<AllowUnsafeBlocks>true</AllowUnsafeBlocks>')
844859
end
845860
end
846-
847-
function dotnetbase.output_global_json(prj)
848-
if prj.dotnetsdk == "MSTest" then
849-
local globaljson = json.decode(io.readfile(path.join(prj.workspace.location, "global.json"))) or {}
850-
globaljson["msbuild-sdks"] = globaljson["msbuild-sdks"] or {}
851-
globaljson["msbuild-sdks"]["MSTest.Sdk"] = "3.6.1"
852-
853-
_p(json.encode(globaljson))
854-
end
855-
end
856-
function dotnetbase.generate_global_json(prj)
857-
local content = p.capture(function() dotnetbase.output_global_json(prj) end)
858-
if content ~= nil and #content > 0 then
859-
p.generate(prj, path.join(prj.workspace.location, "global.json"), function() p.outln(content) end)
860-
end
861-
end

0 commit comments

Comments
 (0)