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

.NET Core 3.0, csprojs cleanup, add generic setup #69

Merged
merged 4 commits into from Oct 4, 2019

Conversation

@Xeinaemm
Copy link
Contributor

@Xeinaemm Xeinaemm commented Sep 29, 2019

Changesets:

  • .NET Core 3.0
  • Moved csproj's targets, properties, references into Directory.Build.targets, Directory.Build.props and Packages.props - one configuration, many projects
  • Moved container and startup initialization into Infrastructure.

Directory.Build.Targets manage targets that's we want to define inside csproj's.

Directory.Build.props manage common properties that can be shared across projects.

Packages.props defines a list of packages and it's versions - version changed inside this file will change all references. You cannot add package inside a project without definition in Packages.props.

This change introduces the deterministic approach to build applications. Projects should be clean, stupid. More generic abstractions like solutions or build system should know how to deploy a project.

Everything base on the project Jarvis. This approach working at my client's systems that deploying more than 50 systems parallelly. Azure DevOps invoke orchestrator(Cake) that know how to deploy systems.

In DeploymentSettings.props I added an example of custom flag DeployNugetPackages that deploy packages automatically into the local repository(C:\NugetSource - windows based directory) that use nuget.config. I turned off this approach at this moment because NuGet is greedy and without valid source will fail(no folder, Linux, etc.). This approach gives the fast development of packages because they are available after the build.

I wanted to split web with infrastructure and core because it's possible with this approach and will give deterministic result but we are using DTOs inside web so I abandoned this approach at this moment.

@Xeinaemm
Copy link
Contributor Author

@Xeinaemm Xeinaemm commented Sep 29, 2019

Done. Now agent should target .NET Core 3.0 and .NET Standard 2.1, without that will not work.

PS. My orchestrator handled the change from .NET Core 2.2 to 3.0 without any problem. Build Status

@Xeinaemm Xeinaemm mentioned this pull request Sep 29, 2019
@ardalis
Copy link
Owner

@ardalis ardalis commented Sep 30, 2019

How does this compare to my branch? https://github.com/ardalis/CleanArchitecture/tree/ardalis/net30update

Now that 3.0 is RTM, I suppose it makes sense to have master default to it, and to just tag 2.2 for those who will still want to use that. I could probably create a 2.2 Release as well. I just don't want to force all users to have to use 3.0 if they can't upgrade yet.

@Xeinaemm
Copy link
Contributor Author

@Xeinaemm Xeinaemm commented Sep 30, 2019

Answering your question. In ~80% this same code if we're speaking about migration from 2.2 to 3.0.
Differences:

  • I keep IWebHostBuilder because I don't need a custom implementation of Autofac because initialization goes from Infrastructure. I learned from the migration of 150 services from Unity to Autofac that one project(eg. Infrastructure.Setup) should keep information about initialization because the client had 6 types of initializations(Web, API, ReadApi, NServiceBus, WCF, Tests - 100 lines avg. each initialization in one solution). Copy-paste approach was the tedious and error-prone, so generic initialization went to the shared library. Shared project(eg. Infrastructure.Setup) have only minimum information that needs to fill. In some rare cases executing assemblies fill container too but only by action method.
  • Program.cs MVC methods changed to:
services.AddControllersWithViews().AddNewtonsoftJson();
services.AddRazorPages();

and

app.UseEndpoints(endpoints =>
{
	endpoints.MapDefaultControllerRoute();
	endpoints.MapRazorPages();
});
  • DbContext implementation moved to Infrastructure.
  • Swagger working :-)

Everything else it's only cleanup of references and targets. Projects have minimum information about custom deploy settings.

Good point, additional branch as 2.2 before migration to keep two versions until 3.1 LTS.

<OutputType>Exe</OutputType>
<PackageId>CleanArchitecture.Web</PackageId>
<WebProjectMode>true</WebProjectMode>

This comment has been minimized.

@ardalis

ardalis Oct 4, 2019
Owner

What's this?

This comment has been minimized.

@Xeinaemm

Xeinaemm Oct 4, 2019
Author Contributor

Custom flag. Common setup for the web can be shared and by enabling flag we don't need to copy-paste configuration in each project. This setup can be found here:

<ItemGroup Condition="'$(WebProjectMode)' == 'true'">
<Content Update="wwwroot\**\*;Views\**\*;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.8.391" />
<Content Update="Pages\_ViewImports.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Pages\_ViewStart.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>

This same approach for tests:



setup:

<ItemGroup Condition="'$(TestProjectMode)' == 'true'">
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<PackageReference Include="coverlet.msbuild" Version="2.7.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" PrivateAssets="all" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" PrivateAssets="all" />
</ItemGroup>

and
<PropertyGroup Condition="'$(TestProjectMode)' == 'true'">
<IsPackable>false</IsPackable>
</PropertyGroup>

This comment has been minimized.

@Xeinaemm

Xeinaemm Oct 4, 2019
Author Contributor

This approach gives predictable results because scripts, custom setups are defined inside a shared solution so the configuration of the additional projects is dynamic and simple in most cases - we know what we want from tests, web, libraries.

@ardalis ardalis merged commit 7f78aad into ardalis:master Oct 4, 2019
1 check failed
1 check failed
ardalis.CleanArchitecture Build #20190929.3 failed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.