Skip to content

Commit 9b3df4b

Browse files
Walluceasottile
authored andcommitted
Handling multiple outputs from dotnet pack
1 parent 26a3e6f commit 9b3df4b

File tree

8 files changed

+101
-15
lines changed

8 files changed

+101
-15
lines changed

pre_commit/languages/dotnet.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,19 @@ def install_environment(
5959

6060
# Determine tool from the packaged file <tool_name>.<version>.nupkg
6161
build_outputs = os.listdir(os.path.join(prefix.prefix_dir, build_dir))
62-
if len(build_outputs) != 1:
63-
raise NotImplementedError(
64-
f"Can't handle multiple build outputs. Got {build_outputs}",
62+
for output in build_outputs:
63+
tool_name = output.split('.')[0]
64+
65+
# Install to bin dir
66+
helpers.run_setup_cmd(
67+
prefix,
68+
(
69+
'dotnet', 'tool', 'install',
70+
'--tool-path', os.path.join(envdir, BIN_DIR),
71+
'--add-source', build_dir,
72+
tool_name,
73+
),
6574
)
66-
tool_name = build_outputs[0].split('.')[0]
67-
68-
# Install to bin dir
69-
helpers.run_setup_cmd(
70-
prefix,
71-
(
72-
'dotnet', 'tool', 'install',
73-
'--tool-path', os.path.join(envdir, BIN_DIR),
74-
'--add-source', build_dir,
75-
tool_name,
76-
),
77-
)
7875

7976
# Clean the git dir, ignoring the environment dir
8077
clean_cmd = ('git', 'clean', '-ffxd', '-e', f'{ENVIRONMENT_DIR}-*')
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- id: dotnet-example-hook
2+
name: Test Project 1
3+
description: Test Project 1
4+
entry: proj1
5+
language: dotnet
6+
stages: [commit]
7+
- id: proj2
8+
name: Test Project 2
9+
description: Test Project 2
10+
entry: proj2
11+
language: dotnet
12+
stages: [commit]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30114.105
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proj1", "proj1\proj1.csproj", "{38A939C3-DEA4-47D7-9B75-0418C4249662}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "proj2", "proj2\proj2.csproj", "{4C9916CB-165C-4EF5-8A57-4CB6794C1EBF}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{38A939C3-DEA4-47D7-9B75-0418C4249662}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{38A939C3-DEA4-47D7-9B75-0418C4249662}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{38A939C3-DEA4-47D7-9B75-0418C4249662}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{38A939C3-DEA4-47D7-9B75-0418C4249662}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{4C9916CB-165C-4EF5-8A57-4CB6794C1EBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{4C9916CB-165C-4EF5-8A57-4CB6794C1EBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{4C9916CB-165C-4EF5-8A57-4CB6794C1EBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{4C9916CB-165C-4EF5-8A57-4CB6794C1EBF}.Release|Any CPU.Build.0 = Release|Any CPU
27+
EndGlobalSection
28+
EndGlobal
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace proj1
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
Console.Write("Hello from dotnet!\n");
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
7+
<PackAsTool>true</PackAsTool>
8+
<ToolCommandName>proj1</ToolCommandName>
9+
<PackageOutputPath>./nupkg</PackageOutputPath>
10+
</PropertyGroup>
11+
12+
</Project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace proj2
4+
{
5+
class Program
6+
{
7+
static void Main(string[] args)
8+
{
9+
Console.WriteLine("Hello World!");
10+
}
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
7+
<PackAsTool>true</PackAsTool>
8+
<ToolCommandName>proj2</ToolCommandName>
9+
<PackageOutputPath>./nupkg</PackageOutputPath>
10+
</PropertyGroup>
11+
12+
</Project>

tests/repository_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,7 @@ def test_local_perl_additional_dependencies(store):
10421042
(
10431043
'dotnet_hooks_csproj_repo',
10441044
'dotnet_hooks_sln_repo',
1045+
'dotnet_hooks_combo_repo',
10451046
),
10461047
)
10471048
def test_dotnet_hook(tempdir_factory, store, repo):

0 commit comments

Comments
 (0)