V1.7.0.0(for .Net 2.0) not working with MSBuild 2.0

Apr 10, 2012 at 1:31 PM

Hello,

 I have just downloaded Yahoo.Yui.Compressor v1.7.0.0(for .Net 2.0).But it seems not working for MSBuild 2.0 version.

I am getting error as :The element <CssFiles> beneath elelment <ItemGroup> is unrecognized.

But if I try Yahoo.Yui.Compressor v1.7.0.0 (for 3.5) with MSBuild 3.5 , works fine.

In short , same MSBuild.xml  works for 3.5 but not with 2.0 version.

Are there any specific configuration for .Net 2.0 version?

Kindly suggest if I am missing something.

 

Regards,

VCP

 

Coordinator
Apr 11, 2012 at 1:22 AM

Hi VCP.

i'm guessing that the MSBuild package is compiled against .NET 3.5. As such, i'm guessng that means that the 2.0 msbuild.exe is different to the 3.5 msbuild.exe

So ... what can we do here?

If you download the source code, you can change the targeting of the MSBuild project to 2.0 .. and if there's anything like List<T> or something, change them over to something that is .net 2.0 compatible AND we need to reference a .net 2.0 version of the MSBuild Tasks dll.

I'm sorry about that .. but that's the quick and simple answer for people on .NET 2.0 (right now).

:(

Apr 13, 2012 at 1:13 PM

Thanks for your reply.

I have downloaded the code which is available at CodePlex, but it is developed in 2008 with fw 3.5; I am getting lot of compilation errors in VS2005, as many of the code constructs works only in 3.5.

Do you have pure 2.0 code available?

 

Regards,

Vidyut

 

 

Coordinator
Apr 13, 2012 at 1:26 PM

Hi VCP.

hmm. the latest source should be a 2.0 NET Language.

Otherwise, here's a link to a checkin that has both 3.5 and 2.0 bindings. Try that :)

Coordinator
Apr 13, 2012 at 2:09 PM

The latest source is developed in a VS2010 project but *targets* the 2.0 framework.  This is separate to the version of msbuild being used.  Is there any reason you have to use msbuild 2.0?

Also, you are trying to build the code in VS2005, which simply won't work - as you say, there are later constructs in there- syntatic sugar really, which the compiler takes care of when it builds a .net 2.0 binary

The only reason to use the .net2.0 binary is if you want to reference the assembly in a 2.0 project, but if you are using the msbuild task then I would have thought you could use a later version of msbuild.....

Coordinator
Apr 13, 2012 at 2:13 PM

Ta Freeranger :)

I totally missed understood the problem. Yep, you're right. Good pickup!

Apr 16, 2012 at 9:16 AM
Edited Apr 16, 2012 at 9:24 AM

Hi Freeranger,

Our application is developed using VS2005 and can be built only with MSBuild 2.0.Unfortunately we can not migrate our application to VS2008 or later version.

We need to incarporate this Compression task in our .PROJ file so both the tasks(Building and Compression) will be done in single go.

Regards,

VCP

Coordinator
Apr 16, 2012 at 9:53 AM

Hi,

you can build 2.0 projects with later versions of msbuild:

http://msdn.microsoft.com/en-us/library/bb383796.aspx

As you can when using a later visual studio - the output is still a .net 2.0 project

but also look here: http://stackoverflow.com/questions/782725/building-an-msbuild-2-0-project-from-3-5

perhaps you could call out to msbuild 3.5 just for the YUICompressor if using MSBuild > 2.0 won't work for you?

Both of these aside though, are you SURE it's a problem with YUI?  The error you report doesn't ,make sense because ItemGroup is supported by 2.0

http://msdn.microsoft.com/en-us/library/646dk05y(v=vs.80).aspx

Might be best if you can post a self-contained full example both working (3.5) and not working (2.0) so we can better diagnose the problem....

Coordinator
Apr 17, 2012 at 8:20 AM

Oh, and one more option, if it all has to be 2.0, and you have VS 2010, is to download the very latest sources (for v 2.0 of YUICompressor) and build the binaries - this targets .net 2.0 and uses the 2.0 msbuild framework.

You will need to look at the MsBuild Example included in the sources to see the new syntax though as it is very much a breaking change.

No binaries as yet for this code, as we're not quite finished with it yet - but this should get you going if none of the other options work...

Apr 20, 2012 at 1:44 PM
Edited Apr 20, 2012 at 1:49 PM

You guys are doing a great job!!!!

Thanks All for your responses.I really appriciate your help so far...I tried Building my 2.0 project  with MSBuild 3.5 using Yui Compressor (for 3.5) and it worked like a charm :)

 Now I could see all my files are getting compressed and combined.I want only compression.Is that possible?

Regards,

VCP

Coordinator
Apr 20, 2012 at 2:52 PM

Hi,

Glad to be of service ;)

So you want one output file per source file?  The solution lies in this thread: http://yuicompressor.codeplex.com/discussions/348246

Apr 23, 2012 at 10:41 AM
Edited Apr 23, 2012 at 10:54 AM

Thanks for this post.But what I require is slightly different.I tried using "%JavaScriptFiles.Identify).min" But this creates a new file. e.g If I want to minify my "ABC".js file, it minifies it with name like "ABC.js.min".js that means it includes .js extention in its file name.Is there any way to retain the original file name after compression? I tried setting "DeleteJavascriptFiles" to "True", but it throws exception as ->" Access to the path ABC.js is denied.Failed to delete path ABC.js,its possible the file is locked?"

Regards,

VCP

 

Coordinator
Apr 23, 2012 at 2:37 PM

Hi,

If the output file is the same as an input file then an exception should be thrown because this then gives no meaning to DeleteJavasciptFiles - if DeleteJavascriptFiles is false, what does this mean when the input and output files are the same?  What does it mean if this is true?  It doesn't make sense in either case, so the only sensible thing to do is to throw an exception and give up - not the exception you see, but a more meaningful one (Which will be checked into the codebase shortly).

Replacing the source files with compressed versions of themselves would seem fraught with problems - what happens the next time you run the build script?  You are compressing an already compressed file.  What if you want to make changes to the source file?  Tough, you just overwrote it with a compressed version.

I would think it would make more sense to retain your original files somewhere to be honest, but if you really want to do this then, once again, msbuild has all the necessary tools to help you - Copy the source files to a temp directory, then compress them to the original directory, something like this:

<Target Name="Minify">
    <ItemGroup>
        <srcJsFiles Include="jsfile1.js "/>
        <srcJsFiles Include="jsfile2.js "/>
        <srcJsFiles Include="jsfile3" />
    </ItemGroup>

    <!-- Make a temp dir to store the files -->
    <MakeDir Condition="!Exists('temp')" Directories="temp" />

    <!-- Copy the source files to the temp dir -->
    <Copy SourceFiles="@(srcJsFiles)" DestinationFolder="temp" />

    <!-- Create a new item group pointing to these files --> 
    <ItemGroup>
        <JsFiles Include="temp\*.js "/>
    </ItemGroup>

    <CompressorTask
        JavaScriptCompressionType="YuiStockCompression"
        JavaScriptFiles="@(JsFiles)"
        EncodingType="Default"
        DeleteJavaScriptFiles="true"
        LineBreakPosition="-1"
        JavaScriptOutputFile="%(JsFiles.Filename)%(JsFiles.Extension)"
        ThreadCulture="iv"
        />

    <!-- Remove the temporary directory -->
    <Exec Command="rmdir temp /S /Q" ContinueOnError="true" />
</Target>

Hopefully this will sort you out!

Apr 23, 2012 at 4:46 PM

Hello,

That's a good solution. But I was thinking to compress files after copying the Build output.

In short, I will 1st run the build which will copy the published site to some destination e.g. \\shared path\Scripts\<my JS files> then in the same .Proj file (MSBuild.xml in your case) I will provide this path as a Source path for my Compression task, so the final published output will contain the compressed files which I will deploy on application server.

e.g MSBuild.exe MsBuild.xml /p:Outputpath=\\shared path /p:Sourcepath=\\shared path\Scripts

That's why I was wondering if we can replace the original files which are copied after a Build....not the source files)...

Please suggest if I am going in wrong direction?

Regards,

VCP

Coordinator
Apr 23, 2012 at 5:24 PM
Hello,

The solution I have given you will do exactly that - the "srcJsFiles" itemgoup contains the list of files in the directory you want to compress them in. You can't overwrite the input files in yuicompressor as I explained, so the solution is to copy the files to a temp directory, compress the files from there, placing the output in the original directory, and then delete the temporary directory.
The end result is as if the files were compressed and overwritten in place, which is what you are trying to achieve,



On 23 Apr 2012, at 16:46, VCP <notifications@codeplex.com> wrote:

From: VCP

Hello,

That's a good solution. But I was thinking to compress files after copying the Build output.

In short, I will 1st run the build which will copy the published site to some destination e.g. \\shared path\Scripts\<my JS files> then in the same .Proj file (MSBuild.xml in your case) I will provide this path as a Source path for my Compression task, so the final published output will contain the compressed files which I will deploy on application server.

e.g MSBuild.exe MsBuild.xml /p:Outputpath=\\shared path /p:Sourcepath=\\shared path\Scripts

That's why I was wondering if we can replace the original files which are copied after a Build....not the source files)...

Please suggest if I am going in wrong direction?

Regards,

VCP

Apr 23, 2012 at 5:36 PM

Thanks freeranger . I will give a try...

Apr 25, 2012 at 8:26 AM

Hi freeranger,

It really worked for me.Thanks for your help.

 

Regards,

VCP

Coordinator
Apr 25, 2012 at 8:53 AM

Glad to be of service ;)