Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add solution file generator #1

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PackageVersion Include="Kysect.CommonLib" Version="0.1.13" />
<PackageVersion Include="Kysect.CommonLib.DependencyInjection" Version="0.1.13" />
<PackageVersion Include="Kysect.DotnetSlnGenerator" Version="0.1.6" />
<PackageVersion Include="Kysect.Editorconfig" Version="1.1.6" />
<PackageVersion Include="Kysect.Editorconfig" Version="1.1.7" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
Expand All @@ -36,5 +36,6 @@
<PackageVersion Include="TestableIO.System.IO.Abstractions" Version="20.0.4" />
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="20.0.4" />
<PackageVersion Include="xunit" Version="2.6.6" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.6" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Kysect.DotnetProjectSystem.Generating;

namespace Kysect.DotnetProjectSystem.Tests.Generating;

public class SolutionFileStringBuilderTests
{
private readonly SolutionFileStringBuilder _sut;

public SolutionFileStringBuilderTests()
{
_sut = new SolutionFileStringBuilder();
}

[Fact]
public void Build_WithoutModification_ReturnTemplateString()
{
var expected = """
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
""";

string slnFileContent = _sut.Build();

slnFileContent.Should().Be(expected);
}

[Fact]
public void Build_AddProject_AddStringWithStringName()
{
string projectName = "Project";
string projectPath = @"Project\Project.csproj";

string slnFileContent = _sut
.AddProject(projectName, projectPath)
.Build();

slnFileContent.Should().Contain($"= \"{projectName}\", \"{projectPath}\",");
}
}
4 changes: 4 additions & 0 deletions Sources/Kysect.DotnetProjectSystem.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Global using directives

global using FluentAssertions;
global using Xunit;
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);CA1707</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<!-- <PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand All @@ -19,6 +21,14 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Kysect.DotnetProjectSystem\Kysect.DotnetProjectSystem.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Text;

namespace Kysect.DotnetProjectSystem.Generating;

public class SolutionFileStringBuilder
{
private readonly StringBuilder _builder;

public SolutionFileStringBuilder()
{
const string header = """
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34310.174
MinimumVisualStudioVersion = 10.0.40219.1
""";

_builder = new StringBuilder();
_builder.AppendLine(header);
}

public string Build()
{
const string footer = """
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
""";

_builder.Append(footer);
return _builder.ToString();
}

public SolutionFileStringBuilder AddProject(string projectName, string projectPath)
{
// TODO: Support generating of unique GUID
string projectDefinition = $$"""
Project("{{{Guid.Empty}}}") = "{{projectName}}", "{{projectPath}}", "{{{Guid.Empty}}}"
EndProject
""";

_builder.AppendLine(projectDefinition);

return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
2 changes: 0 additions & 2 deletions Sources/Kysect.DotnetProjectSystem/Program.cs

This file was deleted.

Loading