2

I'm trying to use the following in a MSBUILD property in my project:

$([System.DateTime]::Now.ToString("MMMM", $([System.Globalization.CultureInfo]::CurrentCulture))) and getting the error:

Error MSB4185: The function "CurrentCulture" on type "System.Globalization.CultureInfo" is not available for execution as an MSBuild property function.

I’m trying to get the equivalent of this: DateTime.Now.ToString("MMMM", CultureInfo.CurrentCulture)

Can anyone suggest how can I fix this in my case.

I'm using it inside a .wixproj that sets ToolsVersion=4.0 in the Project tag. Looking at the log I see that it's using MSBUILD.exe with 12.0.30723.0 version.

I already looked at Error MSB4185: "System.Globalization.CultureInfo" has not been enabled for execution but I need something I can pass in the project instead of setting a commandline property.

Any help here is appreciated.

Regards, Rajesh

Community
  • 1
  • 1
Rajesh Nagpal
  • 1,088
  • 1
  • 9
  • 12

1 Answers1

3

I ended up using MSBUILD Inline Task to workaround this:

    <!--Inline Task for getting the Current Month and Year by executing a C# code inside this MSBUILD task-->
   <UsingTask TaskName="GetCurrentMonthYear" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >

  <ParameterGroup>
    <CurrentMonth ParameterType="System.String" Output="true" />
    <CurrentYear ParameterType="System.Int32" Output="true" />
  </ParameterGroup>

    <Task>
      <Using Namespace="System.Globalization" />
      <Code Type="Fragment" Language="cs">
      CurrentMonth = DateTime.Now.ToString("MMMM", CultureInfo.CurrentCulture);
      CurrentYear = DateTime.Now.Year;
    </Code>
  </Task>

</UsingTask>

  <!--Calling this target before Compile target to set the appropriate properties-->
  <Target Name="SetCurrentMonthYear" BeforeTargets="Compile">

  <GetCurrentMonthYear>
    <Output PropertyName="CurrentMonth" TaskParameter="CurrentMonth" />
    <Output PropertyName="CurrentYear" TaskParameter="CurrentYear" />
  </GetCurrentMonthYear>

  <PropertyGroup>
    <DefineConstants>$(DefineConstants);CurrentMonth=$(CurrentMonth)</DefineConstants>
    <DefineConstants>$(DefineConstants);CurrentYear=$(CurrentYear)</DefineConstants>
  </PropertyGroup>

</Target>
Rajesh Nagpal
  • 1,088
  • 1
  • 9
  • 12