Illegal Characters - JSTargetExtension

May 22, 2012 at 6:13 PM
Edited May 22, 2012 at 6:14 PM

I like how easy this tool is to incorporate into my build process but I'm trying to insert a timestamp into the filename of the minified files. I have not been able to find documentation on fingerprinting with this tool. What I have done is attempt to insert it into the JSTargetExtension. It looks like this:

 <AjaxMin JsSourceFiles="@(JS)" Switches="" JsSourceExtensionPattern="\.js$" JsTargetExtension="$(TodayAndMinExtension)" CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css" />

But I get a error:

 

Error 8 The "AjaxMin" task failed unexpectedly.System.ArgumentException: Illegal characters in path.   at System.IO.Path.CheckInvalidPathChars(String path)   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength)   at System.IO.Path.GetFullPathInternal(String path)   at System.IO.FileInfo..ctor(String fileName)   at Microsoft.Ajax.Minifier.Tasks.AjaxMin.FileIsWritable(String path)   at Microsoft.Ajax.Minifier.Tasks.AjaxMin.MinifyJavaScript()   at Microsoft.Ajax.Minifier.Tasks.AjaxMin.Execute()   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) C:\myproject.csproj

This doesn't even work if TodayAndMinExtension is only set to ".min.js"

Can anyone give me some clues into anything like to this?

 

Pat

Coordinator
May 22, 2012 at 6:43 PM

That's weird. I created a new Console project with a JS file and  added this at the bottom of the .CSPROJ file:

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
  <Target Name="AfterBuild">
    <ItemGroup>
      <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
    </ItemGroup>
    <ItemGroup>
      <CSS Include="**\*.css" Exclude="**\*.min.css" />
    </ItemGroup>
    <AjaxMin
        JsSourceFiles="@(JS)"  JsSourceExtensionPattern="\.js$" JsTargetExtension="$(TodayAndMinExtension)"
        CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css"  />
  </Target>

And then I defined the TodayAndMinExtension variable like this (in the top <PropertyGroup> section:

     <TodayAndMinExtension>.min.js</TodayAndMinExtension>

and then like this:

    <TodayAndMinExtension>FOOBAR.min.js</TodayAndMinExtension>

Both built just fine. Are you sure the TodayAndMinExtension variable is getting set properly? Any chance you can add this red line to your project file, immediately before the <AjaxMin> element:

    <Message Text="JS Target Extension: '$(TodayAndMinExtension)'" Importance="high" />
    <AjaxMin
        JsSourceFiles="@(JS)"  JsSourceExtensionPattern="\.js$" JsTargetExtension="$(TodayAndMinExtension)"
        CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css"  />

and check what it says in the build output? For instance, my build output then has this in it:

AfterBuild:
  JS Target Extension: 'FOOBAR.min.js' 

 

May 22, 2012 at 10:07 PM
Edited May 22, 2012 at 10:10 PM

Thanks for the help. I already had used messages and knew the values were correct. So with nothing else to try I replaced my code with the code you posted, it works for me as well.

The only differences were that the target for my ajaxmin was set as beforebuild, and the property for the min extension was within that target.

Thanks again,

Pat

Coordinator
May 22, 2012 at 10:46 PM

Wow, really? Even more weird! That shouldn't make any difference. I moved the definition down into the AfterBuild target like you said:

  <Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
  <Target Name="AfterBuild">
    <PropertyGroup>
      <TodayAndMinExtension>(FOOBAR).min.js</TodayAndMinExtension>
    </PropertyGroup>
    <ItemGroup>
      <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
    </ItemGroup>
    <ItemGroup>
      <CSS Include="**\*.css" Exclude="**\*.min.css" />
    </ItemGroup>
    <Message Text="JS Target Extension: '$(TodayAndMinExtension)'" Importance="high" />
    <AjaxMin
        JsSourceFiles="@(JS)"  JsSourceExtensionPattern="\.js$" JsTargetExtension="$(TodayAndMinExtension)"
        CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".min.css"  />
  </Target>

and that still works for me, too. I don't know why it wouldn't for you down in the AfterBuild target. Well, is it a potential solution for you to define that property inside the other group, or do you still need me to investigate why it doesn't work inside the AfterBuild for you? If you want me to keep looking, would it be possible for you to create a minimum-repro solution, zip it all up, and send it to me?