Skip to content

Instantly share code, notes, and snippets.

@bleroy
Last active January 8, 2016 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bleroy/b509d5071434ae58c9e2 to your computer and use it in GitHub Desktop.
Save bleroy/b509d5071434ae58c9e2 to your computer and use it in GitHub Desktop.
Tips for the Week in .NET
@sandersaares
Copy link

https://stackoverflow.com/questions/34611919/how-to-package-a-portable-net-library-targeting-net-core

That plus the linked related qustions document my knowledge on how to implement some common NuGet packaging scenarios in the modern way.

@RehanSaeed
Copy link

Colorful.Console. Adds some colour to the console. I contributed string to ASCII Art code to the project recently. It's a very cool project.

IColorful.Console ASCII Example

@RehanSaeed
Copy link

Serilog is a contender for the best logging framework available on .NET at the moment.

Last month I built Serilog.Exceptions to help log exceptions in more detail. Most logging frameworks simply call Exception.ToString() which does not include information from the Data property of an exception and any custom properties.

Here is an example of what you get when you log the notorious DbEntityValidationException from Entity Framework, the information in the EntityValidationErrors property is normally missing when doing Exception.ToString() but is shown when using Serilog.Exceptions:

{
  "Timestamp": "2015-12-07T12:26:24.0557671+00:00",
  "Level": "Error",
  "MessageTemplate": "Hello World",
  "RenderedMessage": "Hello World",
  "Exception": "System.Data.Entity.Validation.DbEntityValidationException: Message",
  "Properties": {
    "ExceptionDetail": {
      "EntityValidationErrors": [
        {
          "Entry": null,
          "ValidationErrors": [
            {
              "PropertyName": "PropertyName",
              "ErrorMessage": "PropertyName is Required.",
              "Type": "System.Data.Entity.Validation.DbValidationError"
            }
          ],
          "IsValid": false,
          "Type": "System.Data.Entity.Validation.DbEntityValidationResult"
        }
      ],
      "Message": "Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.",
      "Data": {},
      "InnerException": null,
      "TargetSite": null,
      "StackTrace": null,
      "HelpLink": null,
      "Source": null,
      "HResult": -2146232032,
      "Type": "System.Data.Entity.Validation.DbEntityValidationException"
    },
    "Source": "418169ff-e65f-456e-8b0d-42a0973c3577"
  }
}

@ignatandrei
Copy link

https://github.com/ignatandrei/Exporter - an Open Source framework to export a List or JSON/CSV data to Excel/Word/PDF

NuGet package at https://www.nuget.org/packages/ExporterWordExcelPDF/

Demo at http://exporter.azurewebsites.net/

@RehanSaeed
Copy link

ASP.NET MVC Boilerplate is a set of advanced ASP.NET MVC 5 & 6 project templates for building secure, fast, robust and adaptable web applications or sites. It provides the minimum amount of code required on top of the default MVC template provided by Microsoft which is very basic. It's available on the Visual Studio Gallery.

The ASP.NET 5 MVC 6 template provides a feature selection wizard which lets you pick from a huge list of options. It makes creating a new project and enabling fully secure HTTPS with advanced security features like strict transport security, content security policy, public key pinning, HTTPS only cookies and anti-forgery tokens a one click process:

IASP.NET MVC Boilerplate Feature Selection Wizard
IASP.NET MVC Boilerplate Feature Selection Wizard
IASP.NET MVC Boilerplate Feature Selection Wizard

@RehanSaeed
Copy link

VerbalExpressions is a very cool project to make regular expressions human readable:

 [TestMethod]
public void TestingIfWeHaveAValidURL()
{
        // Create an example of how to test for correctly formed URLs
        var verbEx = new VerbalExpressions()
                .StartOfLine()
                .Then( "http" )
                .Maybe( "s" )
                .Then( "://" )
                .Maybe( "www." )
                .AnythingBut( " " )
                .EndOfLine();

        // Create an example URL
        var testMe = "https://www.google.com";
        Assert.IsTrue(verbEx.Test( testMe ), "The URL is incorrect");
        Console.WriteLine("We have a correct URL "); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment