copy "$(SolutionDir)\Somesite.Web\Web.config" "$(ProjectDir)$(OutDir)$(TargetFileName).config"
Wednesday, August 5, 2015
C# - Test - Accessing Web.config in Test Context
When having for instance a unit test in one project and the need to get settings from web.config in another project. We can actually copy the web.config when building the unit test project to retrieve the properties like this.
Insert this in Build Events in project settings.
Thursday, July 16, 2015
Saturday, July 4, 2015
Visual Studio - Resharper Code Snippet for Method
It
have bugged med a lot lately that there is no default method template snippet
in Visual studio.
How
this can even be is beyond me, but I found a neat solution:
In
Template Manager in Resharper you can easily add this method yourself. Here:
Click
create New Template in the Templates Explorer.
This will add a strange file in the background that
you can edit and it has No Name as default this name is to be replaced with
your snippet name. So just fill in the Shortcut: box to the right.
And add the code into the template and save.
This is the code for a simple method snippet with
changeable return type:
Now within a class just type method
Saturday, June 27, 2015
Powershell - Run Process as Administrator
Example:
Start-Process powershell_ise -verb runas
Friday, June 26, 2015
C# - Get Web.config Variable Value
Example value in web.config:
<appSettings>
<add key="ClientId" value="123"/>
<add key ="webUrl" value="http://www.nasa.gov/"/>
</appSettings>
C# Get:
using System.Configuration;
string ClientId=ConfigurationManager.AppSettings["ClientId"]
string webUrl=ConfigurationManager.AppSettings["webUrl"]
Jadda jadda null check on string ClientId and webUrl.
Monday, June 8, 2015
C# - Stripping all html from string fast!
Code example:
/// <summary>
/// Compiled regular expression for performance.
/// </summary>
static Regex _htmlRegex = new Regex(@"(?></?\w+)(?>(?:[^>'""]+|'[^']*'|""[^""]*"")*)>", RegexOptions.Compiled); Alternavtive regex = static Regex _htmlRegex = new Regex(@"</?\w+((\s+\w+(\s*=\s*(?:"".*?""|'.*?'|[^'"">\s]+))?)+\s*|\s*)/?>", RegexOptions.Compiled);
/// <summary>
/// Remove HTML from string with compiled Regex.
/// </summary>
public static string StripTagsRegexCompiled(string source)
{
return _htmlRegex.Replace(source, string.Empty);
}
Subscribe to:
Posts (Atom)

