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.

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

How to get the Correlation ID of the current request in SharePoint

SharePoint generates for each request a random GUID which correlates all log messages in the ULS log which are printed during the current request. The Correlation ID is also printed to error pages. If you want more information about an error page you can use the Correlation ID to find the right log messages in the ULS log.

Recently I wanted to get the current request’s Correlation ID to share it with an external webservice to have the same correlation ID in all depending systems.

You can add following code to your ASP page to get the Correlation ID.

 

Alternative for Invoke-SqlCmd

Invoke-SqlCmd ist a great cmdlet for PowerShell for querying SQL databases. But sometimes you don’t want to install the extra requirement SQL Server Management Objects on the server.

Invoke-SqlCmd -ServerInstance $Server -Database $Database -Query "SELECT * FROM Staff"

There’s an simple alternative. Use the .NET classes in the System.Data.SqlClient namespace which are available on every computer which has the .NET framework installed.

function SqlQuery($server, $database, $query)
{
 $connection = New-Object System.Data.SqlClient.SqlConnection
 $connection.ConnectionString = "Server=$server;Database=$database;Integrated Security=True;"
 $connection.Open()
 $command = $connection.CreateCommand()
 $command.CommandText = $query
 $result = $command.ExecuteReader()
 $table = new-object “System.Data.DataTable”
 $table.Load($result)
 $connection.Close()
 return $table
}

SqlQuery $Server $Database "SELECT * FROM Staff"

Modify the window URL without reloading the page

Today I found an easy solution for the problem that if you’re changing the URL of the current window with JavaScript in the traditonal way, unfortenately the whole page will be reloaded.

window.location = "http://peter-doering.com/mynewurl"

You may want to update the URL after you’ve updated parts of the page with an Ajax call. This would enable the users to share the current page as link or to add an bookmark.

HTML5 introduced a new API for manipulating the browsers history. You can use the pushState()-method to change the current page url without page reload.

history.pushState(null, null, "http://peter-doering.com/mynewurl")
history.pushState(null, null, "http://peter-doering.com?id=1234")

Using Visual Studio Code behind a proxy

Microsoft has built a new lightweight IDE Visual Studio Code. Actually VS Code has nothing in common with their traditional full-featured IDE Visual Studio. It’s more like an enhanced Code Editor like the Atom Editor or vim. VS Code is developed with pure JavaScript and it’s based an Electron (UI-Framework) and Node.js.

If you’re using VS Code from within a companies network und you probably may want to install plugins from the Internet, you have to set the proxy settings first. Because VS Code is built for cross-plattform-ability it isn’t aware of the Windows IE proxy settings.

Please open File -> Preferences -> Settings

Add these two lines to the settings.json:

// Place your settings in this file to overwrite the default settings
{
    "http.proxy": "https://proxy.contoso.com",
    "http.proxyStrictSSL": false
}