Categories
PowerShell

Grep on Windows – Searching in all files recursively

There’s no command line tool on Windows like Grep on Linux to search for a specific text in all files recursively. But there’s a simple alternative.

Bash

grep -r "peter" *

PowerShell

ls * -r | sls "peter"
Categories
.NET C#

Lazy Loading with the Lazy class

Did you know the Lazy class in the System namespace?

This little useful helper was introduced with .NET 4. You can use it to lazy initialize properties.

The ResolvePackagePath()-method gets called if the value is needed the first time.
The property IsValueCreated lets you check if the value is already initialized.

Categories
ALM Team Foundation Server VSO

TFS/VSTS agent behind a corporate proxy

Many companies use a http proxy with authentication. Since TFS 2017 the agents are based on .NET Core to be cross-platform. The new agents are unable to obtain the proxy settings from the operating system (Internet Explorer settings).

I’ve found this solution¬†to set a http proxy for the VSTS agents.

  1. Create a file .proxy in the agents root folder and write the proxy in it.

    Example: http://proxy.contoso.org:8080

  2. Username and password can be set with environment variables
    [Environment]::SetEnvironmentVariable("VSTS_HTTP_PROXY_USERNAME", "proxyuser", "User")
    [Environment]::SetEnvironmentVariable("VSTS_HTTP_PROXY_PASSWORD", "proxypassword", "User")

    See also the documentation on GitHub.

Categories
.NET C#

Sending all e-mails in development environment to a local folder

In the app.config/web.config you can use the configuration section <system.net> <mailSettings> <smtp> to configure how to deliver e-mails which are sent using the MailMessage and SmtpClient classes in your program.

In development environment you usually don’t want the e-mails to be delivered. Today I’ve found a awesome configuration option, which enables that all outgoing e-mails go to an local folder or file share as eml files.

app.config / web.config
Sending an e-mail with .NET
Local pickup folder