Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force the culture of a console command

I want to execute a msbuild script using a specific culture (en-US) as one of the tasks is trying to call a web service using aDateTime.ToShortDateString() as a parameter, and my current culture is uncompatible with the server's (english) format.

How to do it without altering my regional settings ?

like image 356
Sébastien Ros - MSFT Avatar asked Dec 15 '25 02:12

Sébastien Ros - MSFT


1 Answers

I ended up by creating a specific task for changing the current culture like this:

public class ChangeCulture : Task
{
    [Required]
    public string Culture { get; set; }

    public override bool Execute()
    {
        Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(Culture);

        return true;
    }
}
like image 72
Sébastien Ros - MSFT Avatar answered Dec 16 '25 21:12

Sébastien Ros - MSFT