Skip to content

Commit

Permalink
Use nuget.config instead of RestoreAdditionalProjectSources.
Browse files Browse the repository at this point in the history
Then adjust the Build script to only use artifacts folder for NativeImport testing
  • Loading branch information
timyhac committed Jul 14, 2024
1 parent 7871787 commit f579d92
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
"ReleaseAll",
"ReleaseLibplctag",
"ReleaseLibplctagNativeImport",
"Restore",
"Test",
"UpdateCoreBinaries"
]
Expand All @@ -111,7 +110,6 @@
"ReleaseAll",
"ReleaseLibplctag",
"ReleaseLibplctagNativeImport",
"Restore",
"Test",
"UpdateCoreBinaries"
]
Expand Down
49 changes: 29 additions & 20 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,40 +34,50 @@ class Build : NukeBuild


Target Clean => _ => _
.Before(Restore)
.Executes(() =>
{
DotNetClean();
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(dir => dir.DeleteDirectory());
ArtifactsDirectory.CreateOrCleanDirectory();
});

Target Restore => _ => _
.Executes(() =>
{
DotNetRestore(s => s
.SetProjectFile(Solution));
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(dir => {
Log.Debug("Deleting {0}", dir);
dir.DeleteDirectory();
});
ArtifactsDirectory.DeleteDirectory();
});

Target Compile => _ => _
.DependsOn(Restore)
.DependsOn(Clean)
.Executes(() =>
{
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetProjectFile(libplctag)
.SetConfiguration(Configuration)
);

DotNetBuild(s => s
.SetProjectFile(libplctag_NativeImport)
.SetConfiguration(Configuration)
.EnableNoRestore()
);
});

Target Test => _ => _
.DependsOn(Compile)
.DependsOn(PackLibplctagNativeImport)
.Executes(() =>
{
var testProject = Solution.GetProject("libplctag.NativeImport.Tests");

DotNetRestore(s => s
.SetProjectFile(testProject)
.SetNoCache(true)
.SetConfigFile(testProject.Directory / "nuget.config")
);

DotNetBuild(s => s
.SetProjectFile(testProject)
.SetConfiguration(Configuration)
.SetNoRestore(true)
);

DotNetTest(s => s
.SetProjectFile(Solution)
.SetConfiguration(Configuration)
.EnableNoRestore()
.SetProjectFile(testProject)
);
});

Expand All @@ -83,11 +93,10 @@ class Build : NukeBuild
.EnableNoRestore()
.SetOutputDirectory(ArtifactsDirectory)
);

});

Target PackLibplctagNativeImport => _ => _
.DependsOn(Test)
.DependsOn(Compile)
.Executes(() =>
{
DotNetPack(s => s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>

<!-- This allows us to use a PackageReference instead of a ProjectReference for libplctag.NativeImport -->
<!-- which we need to test the Nuget package restore feature for the libplctag core files located in /runtimes -->
<RestoreAdditionalProjectSources>../libplctag.NativeImport/bin/Release/</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,11 +16,11 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<!-- Use the highest available version on 1.x -->

<!-- Instead, use the Nuget package which is built - as long as it is still version 1.x -->
<!--<PackageReference Include="libplctag.NativeImport" Version="1.*" />-->
<PackageReference Include="libplctag.NativeImport" Version="1.*" />

</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/libplctag.NativeImport.Tests/nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="buildArtifacts" value="../../artifacts/" />
</packageSources>

<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="Microsoft.*" />
<!--<package pattern="xunit*" />-->
</packageSource>
<packageSource key="buildArtifacts">
<package pattern="libplctag.NativeImport" />
</packageSource>
</packageSourceMapping>
</configuration>

0 comments on commit f579d92

Please sign in to comment.