Skip to content

Commit bb27ea3

Browse files
authored
Merge pull request #2642 from rkm/fix/dotnet-nuget-config
dotnet: ignore nuget source during tool install
2 parents bce513f + c38e0c7 commit bb27ea3

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

pre_commit/languages/dotnet.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import contextlib
44
import os.path
55
import re
6+
import tempfile
67
import xml.etree.ElementTree
78
import zipfile
89
from typing import Generator
@@ -38,6 +39,22 @@ def in_env(prefix: Prefix) -> Generator[None, None, None]:
3839
yield
3940

4041

42+
@contextlib.contextmanager
43+
def _nuget_config_no_sources() -> Generator[str, None, None]:
44+
with tempfile.TemporaryDirectory() as tmpdir:
45+
nuget_config = os.path.join(tmpdir, 'nuget.config')
46+
with open(nuget_config, 'w') as f:
47+
f.write(
48+
'<?xml version="1.0" encoding="utf-8"?>'
49+
'<configuration>'
50+
' <packageSources>'
51+
' <clear />'
52+
' </packageSources>'
53+
'</configuration>',
54+
)
55+
yield nuget_config
56+
57+
4158
def install_environment(
4259
prefix: Prefix,
4360
version: str,
@@ -85,15 +102,17 @@ def install_environment(
85102
raise AssertionError('"id" element missing tool name')
86103

87104
# Install to bin dir
88-
helpers.run_setup_cmd(
89-
prefix,
90-
(
91-
'dotnet', 'tool', 'install',
92-
'--tool-path', os.path.join(envdir, BIN_DIR),
93-
'--add-source', build_dir,
94-
tool_id,
95-
),
96-
)
105+
with _nuget_config_no_sources() as nuget_config:
106+
helpers.run_setup_cmd(
107+
prefix,
108+
(
109+
'dotnet', 'tool', 'install',
110+
'--configfile', nuget_config,
111+
'--tool-path', os.path.join(envdir, BIN_DIR),
112+
'--add-source', build_dir,
113+
tool_id,
114+
),
115+
)
97116

98117
# Clean the git dir, ignoring the environment dir
99118
clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*')

0 commit comments

Comments
 (0)