Skip to content

Commit 00d11dd

Browse files
committed
add installDotNet() helper
1 parent 39947fb commit 00d11dd

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

scripts/installDotNet.m

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
%% INSTALL_DOTNET install the .NET SDK
2+
% this can be used with dotnetenv() etc.
3+
% https://www.mathworks.com/help/matlab/ref/dotnetenv.html
4+
5+
function installDir = installDotNet(installDir)
6+
arguments
7+
installDir (1,1) string = ""
8+
end
9+
10+
root = fileparts(fileparts(mfilename('fullpath')));
11+
addpath(root)
12+
13+
if ispc()
14+
cmd = "winget install Microsoft.DotNet.SDK.9";
15+
else
16+
17+
if ~strlength(installDir)
18+
if ispc()
19+
installDir = getenv("USERPROFILE");
20+
else
21+
installDir = getenv("HOME");
22+
end
23+
installDir = fullfile(installDir, '.dotnet');
24+
end
25+
if ~isfolder(installDir)
26+
mkdir(installDir);
27+
end
28+
29+
url = 'https://dot.net/v1/dotnet-install.sh';
30+
31+
scr = websave(fullfile(installDir, 'dotnet-install.sh'), url);
32+
33+
cmd = sprintf('sh -c "%s --install-dir %s"', scr, installDir);
34+
35+
assert(stdlib.set_permissions(scr, 0, 0, 1), sprintf("chmod +x %s", scr))
36+
end
37+
38+
disp(cmd)
39+
40+
s = system(cmd);
41+
ok = 0;
42+
if ispc()
43+
ok(end+1) = -1978335189;
44+
end
45+
if ~stdlib.is_matlab_online()
46+
assert(ismember(s, ok))
47+
end
48+
49+
if isunix()
50+
setenv("DOTNET_ROOT", installDir)
51+
52+
disp("add to " + fullfile(userpath, 'startup.m') + " the line:")
53+
disp("setenv('DOTNET_ROOT','" + installDir + "')")
54+
55+
[~, m] = system(sprintf('%s/dotnet --info', installDir));
56+
disp(m)
57+
end
58+
59+
assert(NET.isNETSupported)
60+
61+
dotnetenv()
62+
63+
end

0 commit comments

Comments
 (0)