Skip to content
This repository was archived by the owner on Jul 18, 2024. It is now read-only.

Commit 33804c0

Browse files
Improved build
1 parent b564a04 commit 33804c0

13 files changed

+64
-62
lines changed

.run/Build.run.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Build" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/Build/bin/Debug/net8.0/Build.exe" />
4-
<option name="PROGRAM_PARAMETERS" value="" />
4+
<option name="PROGRAM_PARAMETERS" value="-p version=1.0.0-beta" />
55
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
66
<option name="PASS_PARENT_ENVS" value="1" />
77
<option name="USE_EXTERNAL_CONSOLE" value="0" />

.run/Samples Build.run.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="Samples Build" type="DotNetProject" factoryName=".NET Project">
33
<option name="EXE_PATH" value="$PROJECT_DIR$/Samples/Build/bin/Debug/net8.0/Build.exe" />
4-
<option name="PROGRAM_PARAMETERS" value="" />
4+
<option name="PROGRAM_PARAMETERS" value="-p:version=1.0.0" />
55
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/Samples/DemoProject/MySampleLib" />
66
<option name="PASS_PARENT_ENVS" value="1" />
77
<option name="USE_EXTERNAL_CONSOLE" value="0" />

Build/Program.cs

+51-45
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using HostApi;
1+
using System.Runtime.InteropServices;
2+
using HostApi;
23
using JetBrains.TeamCity.ServiceMessages.Write.Special;
34
using NuGet.Versioning;
45
using static Tools;
@@ -16,6 +17,7 @@
1617
return 1;
1718
}
1819

20+
const string defaultNuGetSource = "https://api.nuget.org/v3/index.json";
1921
var configuration = GetProperty("configuration", "Release");
2022
var apiKey = GetProperty("apiKey", "");
2123
var integrationTests = bool.Parse(GetProperty("integrationTests", UnderTeamCity.ToString()));
@@ -67,33 +69,49 @@
6769

6870
foreach (var package in packages)
6971
{
70-
var path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages", package.Id, packageVersion.ToString());
71-
if (Directory.Exists(path))
72+
var nuGetPackagePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages", package.Id, packageVersion.ToString());
73+
if (Directory.Exists(nuGetPackagePath))
7274
{
73-
Directory.Delete(path, true);
75+
Directory.Delete(nuGetPackagePath, true);
76+
}
77+
78+
var packageOutput = Path.GetDirectoryName(package.Package);
79+
if (Directory.Exists(packageOutput))
80+
{
81+
Directory.Delete(packageOutput, true);
7482
}
7583
}
7684

7785
var buildProps = new[] {("version", packageVersion.ToString())};
78-
Succeed(new DotNetBuild()
86+
Succeed(new MSBuild()
87+
.WithProject(Path.Combine(currentDir, "CSharpInteractive", "CSharpInteractive.Tool.csproj"))
88+
.WithRestore(true)
89+
.WithTarget("Rebuild;GetDependencyTargetPaths")
90+
.WithProps(buildProps)
91+
.Build());
92+
93+
Succeed(new DotNetPack()
7994
.WithProject(solutionFile)
8095
.WithConfiguration(configuration)
8196
.WithProps(buildProps)
8297
.Build());
8398

84-
var reportDir = Path.Combine(currentDir, ".reports");
85-
if (Directory.Exists(reportDir))
99+
foreach (var package in packages)
86100
{
87-
Directory.Delete(reportDir, true);
101+
if (!File.Exists(package.Package))
102+
{
103+
Error($"The NuGet package {package.Package} was not found.");
104+
return 1;
105+
}
106+
107+
GetService<ITeamCityWriter>().PublishArtifact($"{package.Package} => .");
88108
}
89109

90-
var test =
91-
new DotNetTest()
92-
.WithProject(solutionFile)
93-
.WithConfiguration(configuration)
94-
.WithNoBuild(true)
95-
.WithProps(buildProps)
96-
.WithFilter("Integration!=true&Docker!=true");
110+
var test = new DotNetTest()
111+
.WithProject(solutionFile)
112+
.WithConfiguration(configuration)
113+
.WithProps(buildProps)
114+
.WithFilter("Integration!=true&Docker!=true");
97115

98116
var coveragePercentage = 0;
99117
var skipTests = bool.Parse(GetProperty("skipTests", "false"));
@@ -103,6 +121,7 @@
103121
}
104122
else
105123
{
124+
var reportDir = Path.Combine(currentDir, ".reports");
106125
var dotCoverSnapshot = Path.Combine(reportDir, "dotCover.dcvr");
107126
Succeed(
108127
test
@@ -138,37 +157,24 @@
138157
}
139158
}
140159

141-
foreach (var package in packages)
142-
{
143-
var packageOutput = Path.GetDirectoryName(package.Package);
144-
if (Directory.Exists(packageOutput))
145-
{
146-
Directory.Delete(packageOutput, true);
147-
}
148-
149-
Succeed(new DotNetPack()
150-
.WithConfiguration(configuration)
151-
.WithProps(buildProps)
152-
.WithProject(package.Project)
153-
.Build());
154-
155-
if (!File.Exists(package.Package))
156-
{
157-
Error($"The NuGet package {package.Package} was not found.");
158-
return 1;
159-
}
160-
161-
GetService<ITeamCityWriter>().PublishArtifact($"{package.Package} => .");
162-
}
163-
164160
var uninstallTool = new DotNetCustom("tool", "uninstall", toolPackageId, "-g")
165161
.WithShortName("Uninstalling tool");
166162

167-
if (uninstallTool.Run(output => WriteLine(output.Line)) != 0)
163+
if (uninstallTool.Run(_ => { } ) != 0)
168164
{
169165
Warning($"{uninstallTool} failed.");
170166
}
171167

168+
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
169+
{
170+
var toolsDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet", "tools");
171+
var pathEnvVar = Environment.GetEnvironmentVariable("PATH");
172+
Info($"Prev PATH={pathEnvVar}");
173+
pathEnvVar = $"{pathEnvVar}:{toolsDir}";
174+
Info($"New PATH={pathEnvVar}");
175+
Environment.SetEnvironmentVariable("PATH", pathEnvVar);
176+
}
177+
172178
var installTool = new DotNetCustom("tool", "install", toolPackageId, "-g", "--version", packageVersion.ToString(), "--add-source", Path.Combine(outputDir, "CSharpInteractive.Tool"))
173179
.WithShortName("Installing tool");
174180

@@ -179,29 +185,29 @@
179185

180186
Succeed(new DotNetCustom("csi", "/?").Run(), "Checking tool");
181187

182-
var uninstallTemplates = new DotNetCustom("new", "-u", templatesPackageId)
188+
var uninstallTemplates = new DotNetCustom("new", "uninstall", templatesPackageId)
183189
.WithShortName("Uninstalling template");
184190

185191
if (uninstallTemplates.Run(output => WriteLine(output.Line)) != 0)
186192
{
187193
Warning($"{uninstallTemplates} failed.");
188194
}
189195

190-
var installTemplates = new DotNetCustom("new", "-i", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
196+
var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
191197
.WithShortName("Installing template");
192198

193199
Succeed(installTemplates.Run(), installTemplates.ShortName);
194200

195201
foreach (var framework in frameworks)
196202
{
197-
var buildProjectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..8]);
203+
var buildProjectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4]);
198204
Directory.CreateDirectory(buildProjectDir);
199205
var sampleProjectName = $"sample project for {framework}";
200206
try
201207
{
202208
var sampleProjectDir = Path.Combine("Samples", "DemoProject", "MySampleLib", "MySampleLib.Tests");
203-
Succeed(new DotNetCustom("new", "build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).Run(), $"Creating a new {sampleProjectName}");
204-
Succeed(new DotNetBuild().WithProject(buildProjectDir).AddSources(Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build());
209+
Succeed(new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore").WithWorkingDirectory(buildProjectDir).Run(), $"Creating a new {sampleProjectName}");
210+
Succeed(new DotNetBuild().WithProject(buildProjectDir).WithSources(defaultNuGetSource, Path.Combine(outputDir, "CSharpInteractive")).WithShortName($"Building the {sampleProjectName}").Build());
205211
Succeed(new DotNetRun().WithProject(buildProjectDir).WithNoBuild(true).WithWorkingDirectory(sampleProjectDir).Run(), $"Running a build for the {sampleProjectName}");
206212
Succeed(new DotNetCustom("csi", Path.Combine(buildProjectDir, "Program.csx")).WithWorkingDirectory(sampleProjectDir).Run(), $"Running a build as a C# script for the {sampleProjectName}");
207213
}
@@ -213,7 +219,7 @@
213219

214220
if (!string.IsNullOrWhiteSpace(apiKey) && packageVersion.Release != "dev" && packageVersion.Release != "dev")
215221
{
216-
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources("https://api.nuget.org/v3/index.json");
222+
var push = new DotNetNuGetPush().WithApiKey(apiKey).WithSources(defaultNuGetSource);
217223
foreach (var package in packages.Where(i => i.Publish))
218224
{
219225
Succeed(push.WithPackage(package.Package).Run(), $"Pushing {Path.GetFileName(package.Package)}");

CSharpInteractive.Templates/CSharpInteractive.Templates.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<PropertyGroup>
44
<TargetFramework/>
55
<TargetFrameworks>netstandard1.0</TargetFrameworks>
6+
<IsPackable>true</IsPackable>
67
<IncludeBuildOutput>False</IncludeBuildOutput>
78
<IncludeSource>False</IncludeSource>
89
<IncludeContentInPack>true</IncludeContentInPack>
910
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
1011
<EnableDefaultItems>False</EnableDefaultItems>
11-
<IsPackable>true</IsPackable>
1212
<NoWarn>2008;NU5105</NoWarn>
1313
<NoPackageAnalysis>true</NoPackageAnalysis>
1414
<PackageId>CSharpInteractive.Templates</PackageId>

CSharpInteractive.Tests/CSharpInteractive.Tests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<ItemGroup>
1111
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0"/>
1212
<PackageReference Include="Moq" Version="4.20.70"/>
13-
<PackageReference Include="Pure.DI" Version="2.1.23">
13+
<PackageReference Include="Pure.DI" Version="2.1.24">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>
@@ -25,7 +25,7 @@
2525
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13"/>
2626
<ProjectReference Include="..\CSharpInteractive.HostApi\CSharpInteractive.HostApi.csproj"/>
2727
<ProjectReference Include="..\CSharpInteractive\CSharpInteractive.Tool.csproj"/>
28-
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.0-cs" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
28+
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.32" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
2929
</ItemGroup>
3030

3131
<PropertyGroup>

CSharpInteractive/CSharpInteractive.Tool.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<PackageReference Include="NuGet.Build.Tasks" Version="6.4.0"/>
3434
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" IncludeAssets="all"/>
3535
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" IncludeAssets="all"/>
36-
<PackageReference Include="Pure.DI" Version="2.1.23">
36+
<PackageReference Include="Pure.DI" Version="2.1.24">
3737
<PrivateAssets>all</PrivateAssets>
3838
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3939
</PackageReference>
@@ -43,7 +43,7 @@
4343
</PackageReference>
4444
<PackageReference Include="TeamCity.ServiceMessages" Version="4.1.1"/>
4545
<ProjectReference Include="..\CSharpInteractive.HostApi\CSharpInteractive.HostApi.csproj" PrivateAssets="all"/>
46-
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.0-cs" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
46+
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.32" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
4747
<InternalsVisibleTo Include="CSharpInteractive.Tests"/>
4848
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
4949
</ItemGroup>

CSharpInteractive/CSharpInteractive.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<PackageReference Include="NuGet.Build.Tasks" Version="6.4.0"/>
2828
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" IncludeAssets="all"/>
2929
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" IncludeAssets="all"/>
30-
<PackageReference Include="Pure.DI" Version="2.1.23">
30+
<PackageReference Include="Pure.DI" Version="2.1.24">
3131
<PrivateAssets>all</PrivateAssets>
3232
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
3333
</PackageReference>
@@ -37,7 +37,7 @@
3737
</PackageReference>
3838
<PackageReference Include="TeamCity.ServiceMessages" Version="4.1.1"/>
3939
<ProjectReference Include="..\CSharpInteractive.HostApi\CSharpInteractive.HostApi.csproj" PrivateAssets="all" GeneratePathProperty="true" IncludeAssets="All"/>
40-
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.0-cs" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
40+
<PackageReference Include="TeamCity.DotNet.Integration" Version="1.0.32" PrivateAssets="all" GeneratePathProperty="true" ExcludeAssets="All" IncludeAssets="none"/>
4141
<InternalsVisibleTo Include="CSharpInteractive.Tests"/>
4242
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
4343
</ItemGroup>
Binary file not shown.

build.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
%DOTNET_ROOT%/dotnet.exe run -f net8.0 --project Build -- -p integrationTests=true -p version=1.0.0-beta
1+
dotnet run -f net8.0 --project Build -- -p integrationTests=true -p version=1.0.0-beta

build.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
dotnet run -f net8.0 --project Build -- -p integrationTests=true -p version=1.0.0-beta

docker.cmd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
docker.exe pull nikolayp/dotnetsdk:latest
2-
docker.exe run --rm -it -v D:\Projects\csharp-interactive:/src -w /src nikolayp/dotnetsdk:latest dotnet build
2+
docker.exe run --rm -it -v D:\Projects\csharp-interactive:/src -w /src nikolayp/dotnetsdk:latest dotnet run -f net8.0 --project Build

icon.png

3.99 KB
Loading

nuget.config

-6
This file was deleted.

0 commit comments

Comments
 (0)