Skip to content

Commit

Permalink
Feature: Add nuget package (#334)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description 💬
<!--- Describe your changes in detail -->

## Motivation and Context 🥅
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

## How has this been tested? 🧪
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how
-->
<!--- your change affects other areas of the code, etc. -->
- [ ] Local build ⚒️
- [ ] Local tests 🧪
- [ ] (optional) Local run and endpoint tested in swagger 🚀

## Screenshots (if appropriate) 💻

## Types of changes 🌊
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

## Checklist ☑️

<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [x] The pull request title starts with the jira case number (when
applicable), e.g. "TEST-1234 Add some feature"
- [x] The person responsible for following up on requested review
changes has been assigned to the pull request
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.

## Highly optional checks, only use these if you have a reason to do so
✔️

- [ ] This PR changes the database so I have added the *create-diagram*
label to assist reviewers with a db diagram
- [ ] This PR changes platform or backend and I need others to be able
to test against these changes before merging to dev, so I have added the
*deploy-azure* label to deploy before merging the PR

## Checklist for the approver ✅

- [ ] I've checked the files view for spelling issues, code quality
warnings and similar
- [ ] I've waited until all checks have passed (green check/without
error)
- [ ] I've checked that only the intended files are changed
  • Loading branch information
hwinther authored Nov 1, 2024
1 parent 6299cbd commit 66e0a90
Show file tree
Hide file tree
Showing 13 changed files with 556 additions and 1 deletion.
152 changes: 152 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

[*.{blockshader,c,c++,c++m,cc,ccm,cginc,compute,cp,cpp,cppm,cshtml,cu,cuh,cxx,cxxm,fx,fxh,h,h++,hh,hlsl,hlsli,hlslinc,hp,hpp,htm,html,hxx,icc,inc,inl,ino,ipp,ixx,mpp,mq4,mq5,mqh,mxx,razor,shaderFoundry,tcc,tpp,urtshader,usf,ush}]
indent_style = tab
indent_size = tab
tab_width = 4

[*.{asax,ascx,aspx,axaml,cs,master,paml,skin,vb,xaml,xamlx,xoml}]
indent_style = space
indent_size = 4
tab_width = 4

[*.{appxmanifest,axml,build,config,csproj,dbml,discomap,dtd,jsproj,lsproj,njsproj,nuspec,proj,props,resw,resx,StyleCop,targets,tasks,vbproj,xml,xsd}]
indent_style = space
indent_size = 2
tab_width = 2

[*]

# Microsoft .NET properties
csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion
csharp_space_after_cast = true
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion

# ReSharper properties
resharper_align_linq_query = true
resharper_align_multiline_argument = true
resharper_align_multiline_calls_chain = true
resharper_align_multiline_extends_list = true
resharper_align_multiline_for_stmt = true
resharper_align_multiline_parameter = true
resharper_align_multiple_declaration = true
resharper_align_multline_type_parameter_constrains = true
resharper_align_tuple_components = true
resharper_apply_on_completion = true
resharper_blank_lines_after_multiline_statements = 1
resharper_blank_lines_around_auto_property = 0
resharper_blank_lines_around_property = 0
resharper_braces_for_for = required_for_multiline
resharper_braces_for_foreach = required_for_multiline
resharper_braces_for_while = required
resharper_constructor_or_destructor_body = expression_body
resharper_csharp_blank_lines_around_field = 0
resharper_csharp_blank_lines_around_invocable = 0
resharper_csharp_keep_blank_lines_in_code = 1
resharper_csharp_keep_blank_lines_in_declarations = 1
resharper_csharp_max_line_length = 250
resharper_csharp_outdent_commas = true
resharper_csharp_wrap_arguments_style = chop_if_long
resharper_csharp_wrap_multiple_type_parameter_constraints_style = wrap_if_long
resharper_indent_nested_fixed_stmt = true
resharper_indent_nested_foreach_stmt = true
resharper_indent_nested_for_stmt = true
resharper_indent_nested_lock_stmt = true
resharper_indent_nested_usings_stmt = true
resharper_indent_nested_while_stmt = true
resharper_keep_existing_declaration_parens_arrangement = false
resharper_keep_existing_expr_member_arrangement = false
resharper_keep_existing_initializer_arrangement = false
resharper_local_function_body = expression_body
resharper_max_attribute_length_for_same_line = 50
resharper_max_initializer_elements_on_line = 1
resharper_method_or_operator_body = expression_body
resharper_new_line_before_while = true
resharper_place_accessorholder_attribute_on_same_line = false
resharper_place_accessor_attribute_on_same_line = false
resharper_place_field_attribute_on_same_line = false
resharper_place_simple_accessorholder_on_single_line = true
resharper_place_simple_accessor_on_single_line = false
resharper_place_simple_embedded_statement_on_same_line = false
resharper_place_simple_initializer_on_single_line = false
resharper_place_simple_property_pattern_on_single_line = false
resharper_qualified_using_at_nested_scope = true
resharper_space_within_single_line_array_initializer_braces = false
resharper_wrap_array_initializer_style = chop_if_long
resharper_wrap_chained_method_calls = chop_always
resharper_wrap_enum_declaration = chop_if_long
resharper_wrap_linq_expressions = chop_always

# ReSharper inspection severities
resharper_annotate_can_be_null_parameter_highlighting = warning
resharper_annotate_can_be_null_type_member_highlighting = warning
resharper_annotate_not_null_parameter_highlighting = warning
resharper_annotate_not_null_type_member_highlighting = warning
resharper_arrange_constructor_or_destructor_body_highlighting = hint
resharper_arrange_local_function_body_highlighting = hint
resharper_arrange_method_or_operator_body_highlighting = hint
resharper_arrange_missing_parentheses_highlighting = hint
resharper_arrange_redundant_parentheses_highlighting = hint
resharper_arrange_this_qualifier_highlighting = hint
resharper_arrange_type_member_modifiers_highlighting = hint
resharper_arrange_type_modifiers_highlighting = hint
resharper_async_void_method_highlighting = warning
resharper_bad_control_braces_indent_highlighting = warning
resharper_bad_declaration_braces_indent_highlighting = warning
resharper_bad_expression_braces_indent_highlighting = warning
resharper_bad_indent_highlighting = warning
resharper_bad_namespace_braces_indent_highlighting = warning
resharper_bad_preprocessor_indent_highlighting = warning
resharper_bad_switch_braces_indent_highlighting = warning
resharper_built_in_type_reference_style_for_member_access_highlighting = hint
resharper_built_in_type_reference_style_highlighting = hint
resharper_cpp_bad_child_statement_indent_highlighting = warning
resharper_cpp_bad_control_braces_indent_highlighting = warning
resharper_cpp_bad_declaration_braces_indent_highlighting = warning
resharper_cpp_bad_expression_braces_indent_highlighting = warning
resharper_cpp_bad_indent_highlighting = warning
resharper_cpp_bad_namespace_braces_indent_highlighting = warning
resharper_cpp_bad_switch_braces_indent_highlighting = warning
resharper_cpp_incorrect_blank_lines_near_braces_highlighting = warning
resharper_cpp_missing_blank_lines_highlighting = warning
resharper_cpp_missing_indent_highlighting = warning
resharper_cpp_outdent_is_off_prev_level_highlighting = warning
resharper_cpp_redundant_blank_lines_highlighting = warning
resharper_cpp_tabs_and_spaces_mismatch_highlighting = warning
resharper_cpp_wrong_indent_size_highlighting = warning
resharper_empty_general_catch_clause_highlighting = error
resharper_function_complexity_overflow_highlighting = error
resharper_incorrect_blank_lines_near_braces_highlighting = warning
resharper_lambda_expression_can_be_made_static_highlighting = error
resharper_lambda_expression_must_be_static_highlighting = warning
resharper_loop_can_be_partly_converted_to_query_highlighting = hint
resharper_markup_attribute_typo_highlighting = none
resharper_markup_text_typo_highlighting = none
resharper_missing_blank_lines_highlighting = warning
resharper_missing_indent_highlighting = warning
resharper_nullable_warning_suppression_is_used_highlighting = warning
resharper_outdent_is_off_prev_level_highlighting = warning
resharper_possible_null_reference_exception_highlighting = error
resharper_redundant_base_qualifier_highlighting = warning
resharper_redundant_blank_lines_highlighting = warning
resharper_suggest_var_or_type_built_in_types_highlighting = hint
resharper_suggest_var_or_type_elsewhere_highlighting = hint
resharper_suggest_var_or_type_simple_types_highlighting = hint
resharper_tabs_and_spaces_mismatch_highlighting = warning
resharper_use_configure_await_false_for_async_disposable_highlighting = warning
resharper_use_nameof_expression_for_part_of_the_string_highlighting = warning
resharper_use_positional_deconstruction_pattern_highlighting = hint
resharper_use_throw_if_null_method_highlighting = warning
resharper_wrong_indent_size_highlighting = warning
27 changes: 27 additions & 0 deletions shared/NugetDistSample/NugetDistSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>nuget_distribution_example</PackageId>
<Version>0.0.26</Version>
<Authors>Hans Christian Winther-Sørensen</Authors>
<Company>WSH</Company>
<PackageDescription>Distributing shared project files example</PackageDescription>
<Title>Nuget distribution example</Title>
<Description>Nuget distribution example</Description>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/hwinther/test</RepositoryUrl>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<NoDefaultExcludes>true</NoDefaultExcludes>
<!--NuspecFile>NugetDistSample.nuspec</NuspecFile>
<NuspecProperties>id=$(PackageId);version=$(Version);authors=$(Authors);description=$(Description);title=$(Title);copyright=$(Company)</NuspecProperties-->
</PropertyGroup>
<ItemGroup>
<None Include="readme.md" Pack="true" PackagePath="\" />
<None Include="build\*" Pack="true" PackagePath="build\" />
<None Include="content\**" Pack="true" PackagePath="content\" />
</ItemGroup>
</Project>
17 changes: 17 additions & 0 deletions shared/NugetDistSample/NugetDistSample.nuspec-temp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<description>$description$</description>
<authors>$authors$</authors>
<copyright>$copyright$</copyright>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<license type="expression">MIT</license>
</metadata>
<files>
<!--file src="DistShared.targets" target="build" /-->
<file src="build/DistSample.props" target="build" />
</files>
</package>
141 changes: 141 additions & 0 deletions shared/NugetDistSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

if (args.Length == 2)
{
var msbuildDir = args[0];
var solutionDir = args[1];
Console.WriteLine($"MsbuildDir: {msbuildDir}");
Console.WriteLine($"SolutionDir: {solutionDir}");

var solutionSignature = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(solutionDir));
var cachePath = Path.Combine(msbuildDir, "..", $"cached-run-{solutionSignature}");
if (Path.Exists(cachePath))
{
Console.WriteLine("Already executed for this solution.");
return;
}

var gitFolderPath = FindGitFolder(solutionDir);
if (gitFolderPath == null)
{
Console.WriteLine(".git folder not found.");
return;
}

Console.WriteLine($".git folder found at: {gitFolderPath}");

var gitIgnorePath = Path.Combine(gitFolderPath, ".gitignore");
AddGitIgnoreLineRegex(gitIgnorePath, "**/.idea/**", IdeaRegex());

RecursivelyCopyContent(Path.Combine(msbuildDir, "..", "content"), gitFolderPath);

var hooksAdded = ExecuteCommandIfLineDoesNotExist(Path.Combine(gitFolderPath, ".git", "config"), "hooksPath = .githooks", "git config --local core.hooksPath .githooks");
Console.WriteLine(hooksAdded ? "Git hooks path set." : "Git hooks path already set.");

File.WriteAllText(cachePath, DateTime.Now.ToString(CultureInfo.InvariantCulture));
}
else
{
Console.WriteLine("Usage: NugetDistSample <MsbuildDir> <SolutionDir>");
}

return;

static string? FindGitFolder(string? directory)
{
while (!string.IsNullOrEmpty(directory))
{
if (Directory.Exists(Path.Combine(directory, ".git")))
return directory;

directory = Directory.GetParent(directory)
?.FullName;
}

return null;
}

static bool ExecuteCommandIfLineDoesNotExist(string filePath, string line, string command)
{
var lines = File.ReadAllLines(filePath);
if (Array.Exists(lines, l => l.Contains(line)))
return false;

Console.WriteLine($"Executing command: {command}");

ProcessStartInfo processStartInfo = new()
{
WorkingDirectory = Path.GetDirectoryName(filePath),
UseShellExecute = false,
CreateNoWindow = true
};

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
processStartInfo.FileName = "cmd";
processStartInfo.Arguments = $"/c {command}";
}
else
{
processStartInfo.FileName = "sh";
processStartInfo.Arguments = $"-c \"{command}\"";
}

var process = Process.Start(processStartInfo);

if (process == null)
return false;

if (process.WaitForExit(5000))
return true;

Console.WriteLine("Timeout waiting for process to exit.");
process.Kill(true);
return false;
}

static void AddGitIgnoreLineRegex(string gitIgnorePath, string line, Regex match)
{
var lines = File.ReadAllLines(gitIgnorePath);
if (Array.Exists(lines, match.IsMatch))
return;

Console.WriteLine($"Adding line to .gitignore: {line}");
File.AppendAllLines(gitIgnorePath,
new[]
{
line
});
}

static void RecursivelyCopyContent(string sourceFolder, string destinationFolder)
{
foreach (var sourceSubFolder in Directory.GetDirectories(sourceFolder))
{
var destinationSubFolder = Path.Combine(destinationFolder, Path.GetFileName(sourceSubFolder));
if (!Directory.Exists(destinationSubFolder))
{
Console.WriteLine($"Creating directory: {destinationSubFolder}");
Directory.CreateDirectory(destinationSubFolder);
}

RecursivelyCopyContent(sourceSubFolder, destinationSubFolder);
}

foreach (var sourceFile in Directory.GetFiles(sourceFolder))
{
var destinationFile = Path.Combine(destinationFolder, Path.GetFileName(sourceFile));

Console.WriteLine($"Copying file: {sourceFile} -> {destinationFile}");
File.Copy(sourceFile, destinationFile, true);
}
}

internal partial class Program
{
[GeneratedRegex(@".*\.idea.*")]
private static partial Regex IdeaRegex();
}
11 changes: 11 additions & 0 deletions shared/NugetDistSample/build/nuget_distribution_example.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project>
<Target Name="DistSampleInit" BeforeTargets="CollectPackageReferences">
<!--Message Text="Dist sample init SolutionDir=$(SolutionDir)" Importance="High" />
<Message Text="Dist sample init MSBuildThisFileDirectory=$(MSBuildThisFileDirectory)" Importance="High" />
<ItemGroup>
<File Include="$(MSBuildThisFileDirectory)..\content\**\*.*"></File>
</ItemGroup>
<Copy SourceFiles="@(File)" DestinationFolder="$(SolutionDir)\"></Copy-->
<Exec Command="dotnet $(MSBuildThisFileDirectory)..\lib\$(TargetFramework)\NugetDistSample.dll $(MSBuildThisFileDirectory) $(SolutionDir)" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Project>
</Project>
Loading

0 comments on commit 66e0a90

Please sign in to comment.