Customize console team culture

I want to execute an msbuild script using a specific culture (en-US), since one of the tasks is trying to call a web service using aDateTime.ToShortDateString () as a parameter, and my current culture is incompatible with the server (English).

How to do this without changing my regional settings?

+3
source share
2 answers

As a result, I created a specific task for changing the current culture as follows:

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

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

        return true;
    }
}
+2
source

If you want to change the culture of your entire application, you can set the culture when the application starts as follows:

Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);

MSDN.

, . ToShortDateString() en-US, . ToString() , , :

aDateTime.ToString("MM/dd/yyyy");

System.Globalization :

System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
string datePattern = culture.DateTimeFormat.ShortDatePattern;
string shortDate = aDateTime.ToString(datePattern);
-1

Source: https://habr.com/ru/post/1727240/


All Articles