Skip to content

Commit 494a276

Browse files
authored
[DotNetPlanner] add installing packages to InstallStage (#142)
1 parent 5e8a21a commit 494a276

File tree

11 files changed

+112
-28
lines changed

11 files changed

+112
-28
lines changed

planner/languages/dotnet/dotnet_planner.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@ func (p *Planner) getPlan(srcDir string) (*plansdk.Plan, error) {
7878
// Error #2. An error for missing `libicu`. Adding nix pkg `icu` didn't help. TODO need to resolve this issue.
7979
RuntimePackages: []string{dotNetPkg},
8080

81-
BuildStage: &plansdk.Stage{
81+
InstallStage: &plansdk.Stage{
8282
InputFiles: []string{"."},
83+
// --packages stores the downloaded packages in a local directory called nuget-packages
84+
// Otherwise, the default location is ~/.nuget/packages,
85+
// which is hard to copy over into StartStage
86+
Command: "dotnet restore --packages nuget-packages",
87+
},
88+
89+
BuildStage: &plansdk.Stage{
8390

8491
// TODO modify this command to reduce image size
8592
//
@@ -88,12 +95,12 @@ func (p *Planner) getPlan(srcDir string) (*plansdk.Plan, error) {
8895
// - for dotnet publish options: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
8996
// - for -r options: https://docs.microsoft.com/en-us/dotnet/core/rid-catalog
9097
// - for publishing a single file: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=cli
91-
Command: "dotnet publish",
98+
Command: "dotnet publish -c Publish --no-restore",
9299
},
93100
StartStage: &plansdk.Stage{
94101
InputFiles: []string{"."},
95102
// TODO to invoke single-executable: ./bin/Debug/net6.0/linux-64/publish/<projectName>
96-
Command: "dotnet run",
103+
Command: "dotnet run -c Publish --no-build",
97104
},
98105
}, nil
99106
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
obj/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
namespace csharp_10_dotnet_6_with_package;
2+
3+
using Newtonsoft.Json;
4+
5+
class Product
6+
{
7+
public string Name;
8+
public DateTime Expiry;
9+
public string[] Sizes;
10+
11+
public Product()
12+
{
13+
Name = "";
14+
Sizes = new string[] {};
15+
}
16+
}
17+
18+
class Program
19+
{
20+
static void Main(string[] args)
21+
{
22+
Product product = new Product();
23+
product.Name = "Apple";
24+
product.Expiry = new DateTime(2008, 12, 28);
25+
product.Sizes = new string[] { "Small" };
26+
27+
string json = JsonConvert.SerializeObject(product);
28+
Console.WriteLine(string.Format("serialized json for {0} is {1}", product, json));
29+
}
30+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net6.0</TargetFramework>
6+
<RootNamespace>csharp_10_dotnet_6_with_package</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
13+
</ItemGroup>
14+
15+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"packages": [],
3+
"shell": {
4+
"init_hook": null
5+
}
6+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"dev_packages": [
3+
"dotnet-sdk"
4+
],
5+
"runtime_packages": [
6+
"dotnet-sdk"
7+
],
8+
"install_stage": {
9+
"command": "dotnet restore --packages nuget-packages",
10+
"input_files": [
11+
"."
12+
]
13+
},
14+
"build_stage": {
15+
"command": "dotnet publish -c Publish --no-restore"
16+
},
17+
"start_stage": {
18+
"command": "dotnet run -c Publish --no-build",
19+
"input_files": [
20+
"."
21+
]
22+
},
23+
"definitions": null
24+
}

testdata/csharp/csharp_10-dotnet_6/plan.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"dotnet-sdk"
77
],
88
"install_stage": {
9-
"command": ""
10-
},
11-
"build_stage": {
12-
"command": "dotnet publish",
9+
"command": "dotnet restore --packages nuget-packages",
1310
"input_files": [
1411
"."
1512
]
1613
},
14+
"build_stage": {
15+
"command": "dotnet publish -c Publish --no-restore"
16+
},
1717
"start_stage": {
18-
"command": "dotnet run",
18+
"command": "dotnet run -c Publish --no-build",
1919
"input_files": [
2020
"."
2121
]

testdata/csharp/csharp_8-dotnet_3/plan.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"dotnet-sdk_3"
77
],
88
"install_stage": {
9-
"command": ""
10-
},
11-
"build_stage": {
12-
"command": "dotnet publish",
9+
"command": "dotnet restore --packages nuget-packages",
1310
"input_files": [
1411
"."
1512
]
1613
},
14+
"build_stage": {
15+
"command": "dotnet publish -c Publish --no-restore"
16+
},
1717
"start_stage": {
18-
"command": "dotnet run",
18+
"command": "dotnet run -c Publish --no-build",
1919
"input_files": [
2020
"."
2121
]

testdata/csharp/csharp_9-dotnet_5/plan.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"dotnet-sdk_5"
77
],
88
"install_stage": {
9-
"command": ""
10-
},
11-
"build_stage": {
12-
"command": "dotnet publish",
9+
"command": "dotnet restore --packages nuget-packages",
1310
"input_files": [
1411
"."
1512
]
1613
},
14+
"build_stage": {
15+
"command": "dotnet publish -c Publish --no-restore"
16+
},
1717
"start_stage": {
18-
"command": "dotnet run",
18+
"command": "dotnet run -c Publish --no-build",
1919
"input_files": [
2020
"."
2121
]

testdata/csharp/csharp_9-dotnet_6/plan.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"dotnet-sdk"
77
],
88
"install_stage": {
9-
"command": ""
10-
},
11-
"build_stage": {
12-
"command": "dotnet publish",
9+
"command": "dotnet restore --packages nuget-packages",
1310
"input_files": [
1411
"."
1512
]
1613
},
14+
"build_stage": {
15+
"command": "dotnet publish -c Publish --no-restore"
16+
},
1717
"start_stage": {
18-
"command": "dotnet run",
18+
"command": "dotnet run -c Publish --no-build",
1919
"input_files": [
2020
"."
2121
]

0 commit comments

Comments
 (0)