Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
closes #1357
  • Loading branch information
belav committed Dec 6, 2024
1 parent 384f7a1 commit 942e61a
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
17 changes: 13 additions & 4 deletions Src/CSharpier.MsBuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ One way to test the changes in the build/* files
- Edit those files at `C:\Users\[Username]\.nuget\packages\csharpier.msbuild\[VersionNumber]\build`
- Ensure you revert those files and make the same changes to the files here.

Another way
- the validate PR GH action does this, currently only uses the net8 sdk
- dotnet pack Src/CSharpier.MsBuild/CSharpier.MsBuild.csproj -o nupkg /p:Version=0.0.1
- docker build -f ./Tests/CSharpier.MsBuild.Test/Dockerfile .
Some automated tests exist
- the validate PR GH action runs these, mostly around framework versions
- cd ./Tests/MsBuild
- ./Run.ps1

Other things that would be really really nice to automate
- exits properly in release when no files formatted
https://github.com/belav/csharpier/issues/1357
- same as above if thing set
- formats files in debug
- formats files if told to in release
- a few scenarios in here I think, compilation errors etc
https://github.com/belav/csharpier/issues/1131
2 changes: 2 additions & 0 deletions Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<NullOutput>/dev/null</NullOutput>
</PropertyGroup>

<!-- https://github.com/belav/csharpier/issues/1131 -->

<Target Name="CSharpierFormatInner" Condition="'$(CSharpier_Bypass)' != 'true'">
<!-- IgnoreExitCode cleans up the output when files aren't formatted and fail the check -->
<!-- &gt; NullOutput suppresses the output from this so that compilation errors will show up a single time -->
Expand Down
5 changes: 5 additions & 0 deletions Tests/MsBuild/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion Tests/MsBuild/Run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ foreach ($scenario in $scenarios) {
Write-Host "::group::$($scenario.name)"

$scenarioPath = Join-Path $basePath $scenario.name
Write-Host $scenarioPath
New-Item $scenarioPath -ItemType Directory | Out-Null

$dockerFile = Join-Path $scenarioPath "DockerFile"
Expand All @@ -38,7 +39,7 @@ RUN dotnet build -c Release
$csprojFile = Join-Path $scenarioPath "Project.csproj"

$csharpierFrameworkVersion = ""
if ($null -ne $scenario.csharpier_frameworkVersion) {
if ([bool]($scenario.PSobject.Properties.name -match "csharpier_frameworkVersion")) {
$csharpierFrameworkVersion = "
<CSharpier_FrameworkVersion>$($scenario.csharpier_frameworkVersion)</CSharpier_FrameworkVersion>
"
Expand Down
8 changes: 4 additions & 4 deletions Tests/MsBuild/Scenarios.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[
{
"name": "sdk:8.0_netstandard2.0",
"name": "sdk-8.0_netstandard2.0",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "netstandard2.0"
},
{
"name": "sdk:8.0_net8.0-windows",
"name": "sdk-8.0_net8.0-windows",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "net8.0-windows"
},
{
"name": "sdk:8.0_net6.0;net7.07",
"name": "sdk-8.0_net6.0;net7.07",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "net6.0;net7.0"
},
{
"name": "sdk:8.0_csharpier-net8.0",
"name": "sdk-8.0_csharpier-net8.0",
"sdk": "mcr.microsoft.com/dotnet/sdk:8.0",
"targetFrameworks": "netstandard2.0",
"csharpier_frameworkVersion": "net8.0"
Expand Down
12 changes: 12 additions & 0 deletions Tests/MsBuild/UnformattedFileCausesError/Project.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CSharpier.MsBuild" Version="0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions Tests/MsBuild/UnformattedFileCausesError/UnformattedFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Net8;

public class Class1
{


}
10 changes: 10 additions & 0 deletions Tests/MsBuild/nuget.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<packageSources>
<add key="Local" value="nupkg" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageSourceMapping>
<packageSource key="Local">
<package pattern="CSharpier.MsBuild" />
</packageSource>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>

0 comments on commit 942e61a

Please sign in to comment.