specify ouput file name flash builder 4 - apache-flex

This should be easy, but I can't find it. I want my .html and .swf files to be named something differently than the project name. Project name is foo, I want the outputs to be bar.html and bar.swf. Thanks.

Flextras was on the right track. You can't change the output filename (even using the "-output" compiler param) if you're compiling in Flash Builder. Not sure why.
The solution that has worked for me has been to use a bit of indirection:
use mxmlc to compile to ApplicationClass.swf
command line copy ApplicationClass.swf to YourCustomSwf.swf
command line run YourCustomSwf.swf
You can do this with either a simple (platform-dependent) build script, or with Flex Ant Tasks. I highly recommend the latter; it's easy to setup, integrates well with Flash Builder, and (as a mostly platform-independent solution) will work in a multi-team multi-OS environment. Here are the above steps as ant tasks that will perform the magic for you:
<project name="sample-build" default="run-your-swf">
<property file="${basedir}/your.properties.file"/>
<target name="compile-your-app">
<mxmlc file="${SOURCE_DIR}/ApplicationFile.mxml" compiler.debug="${IS_DEBUG}" incremental="true" failonerror="true">
<load-config filename="${DEFAULT_FLEX_CONFIG}"/>
<define name="CONFIG::DEBUG" value="${IS_DEBUG}"/>
<define name="CONFIG::FLASH_AUTHORING" value="${IS_FLASH_AUTHORING}"/>
<define name="CONFIG::IS_RELEASE" value="${IS_RELEASE}"/>
</mxmlc>
</target>
<target name="rename-your-swf" depends="compile-your-app">
<copy file="${OUTPUT_DIR}/feed/FeedComponent.swf" tofile="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</target>
<target name="run-your-swf" depends="rename-your-swf">
<exec executable="${STANDALONE_FLASH_DEBUG_PLAYER}">
<arg line="${OUTPUT_DIR}/YourNewSexyFilename.swf"/>
</exec>
</target>
</project>
you need only define all ${VARIABLES} I've listed in "your.properties.file", like so:
FLASH_PLAYER_DEBUG=/Applications/Adobe Flash CS5/Players/Debug/Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger
IS_DEBUG=true
(et cetera)
And anyway - what's in a name? A program by any other name, would be as awesome... B-)

Related

How to use custom tokens with flex ant tasks

I am trying to use the flex ant task to build my Flex project.
Before using ant, I ran the mxmlc command like this:
mxmlc -load-config mxmlc_conf.xml src\project.mxml -output bin-debug +libs=<absolute_path_to>3rdparty\libs +<other_token>=<absoulte_path_to_value>
The thing is now I am supposed to use flex ant tasks and it looks like they disabled (or forgot about) the custom tokens like += as I haven't found a way to pass those to the mxmlc task.
I have tried using:
< mxmlc ...>< arg token value="..." />< /mxmlc>
but that doesn't work.
What I am trying to accomplish is to get rid of hard-coded paths in the mxmlc config-file (mxmlc_conf.xml) and at first I used the custom tokens in mxmlc but now I don't know how to pass paths as variables to the config file.
I can accept suggestions.
Thanks a lot in advance.
I'm trying to do the exact same thing (replace hard-coded paths in the config file) and I'm looking for the same solution.
It seems we might have to abandon the mxmlc task and simply use mxmlc from the command line:
<exec searchpath="true" executable="amxmlc"
dir="${project.build.outputDirectory}">
<env key="PATH"
path="${env.PATH}:/Applications/Adobe\ Flash\ Builder\ 4.5/sdks/4.5.1/bin" />
<arg value="-load-config" />
<arg value="../src/main/resources/dumpConfig.xml" />
<arg value="+libs=/absolute/path/to/3rd/party/libs" />
<arg value="-output" />
<arg
value="${project.build.outputDirectory}/${application.name}.swf" />
<arg value="../src/main/flex/${application.name}.mxml" />
</exec>
Something like this should work. I'm just hoping there's a better way (that is, a way we can actually use the mxml ant target!)
I hope that helps someone...
Try this
<target>
<replace file="mxmlc_conf.xml" token="$${libs}" value="absolute/path/to/3rdparty/libs"/>
<mxmlc ...>
<load-config filename="mxmlc_conf.xml" />
</mxmlc>
<replace file="mxmlc_conf.xml" token="absolute/path/to/3rdparty/libs" value="$${libs}"/>
</target>

Wrapping or Embedding and MP3 in a SWF using Flex's mxmlc compiler

Our Flash web-based applications play lots of audio for narration and sound-effects. Some of our customers have firewall rules that block downloading of MP3 and other audio files. So, we need to wrap those MP3 files in SWFs. In the past, I've written JSFL scripts that automate the Flash IDE and walk through a complicated, fragile set of steps to embed MP3 files into FLAs and then publish those to SWFs. Now, Flex SDK provides the mxmlc compiler. I've mixed ANT into our workflow, and command-line and automated builds have been a joy. So, I want to make transcoding or wrapping of MP3s part of our build process. I've found Embedding Asset at Compile time in Pure AS3, but this will require that I write a script to generate a wrapper class AS file. Is there a cleaner way to wrap or transcode MP3 files into SWFs? I suppose I'm hoping there is a method for passing the mp3 directly to mxmlc and outputting a swf, but any recommendation better than generating actionscript wrapper classes would be greatly appreciated.
Since you are using MXMLC and Ant already, you should consider adding another bit of code to your Ant build script to build your MP3s into a library SWC. You can then build that SWC into the executable SWF (I've left that simple step out of my example below).
Since all you'll need is Ant, doing it this way is no more difficult than how you're already building your SWF. The only real "gotcha" is that you need to embed your files using an MXMLC/SWC-friendly absolute path (e.g. "/myAssets/myasset.mp3") in your code.
Because it has access to Project metadata, Flash Builder "knows" where the root of your project is, allowing it to use relative embed paths. MXMLC doesn't have any of this info. You therefore need to make sure that the embeds are declared to match the absolute location of how the files are stored in the SWC. If you do this, both Flash Builder and MXMLC/Ant will be able to understand your embeds. That way, everybody's happy.
To help you along, below is an example Ant script for building an asset SWC. Here are the key steps, in a nutshell:
Build up a String containing the locations of the files to be included, one by one
Compile those assets into a SWC using MXMLC and a monster-sized set of command-line arguments
The following script will package jpgs, pngs, svgs, ttfs, xml files, properties files and MP3s into a file called "assets.swc". You'll need to include flexTasks.jar (for obvious reasons) and ant-contrib.jar in the appropriate relative locations and set a FLEX_HOME environment variable.
<?xml version="1.0" encoding="utf-8"?>
<project name="My App Builder"
basedir="."
default="buildSWC"
xmlns:antcontrib="antlib:net.sf.antcontrib">
<taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasks.jar"/>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/libs/ant-contrib-1.0b3.jar"/>
<property environment="env"/>
<property name="FLEX_HOME" value="${env.FLEX_HOME}"/>
<property name="ASSETS_FILE" value="assets.swc"/>
<property name="SRC_DIR" value="./src"/>
<!-- Prepare folders for SWC compilation -->
<target name="buildSWC">
<echo message=""/>
<echo message="*****************************************************"/>
<echo message="* ${ASSETS_FILE}"/>
<echo message="*****************************************************"/>
<echo message="...basedir: ${basedir}"/>
<!-- Build a swc from statically-included assets (images, mp3s, xml files, properties files) -->
<fileset id="assets.flex" dir="src" includes="**/*.jpg,**/*.png,**/*.mp3,**/*.css,**/*.svg,**/*.swf,**/*.TTF,**/*.jpeg,**/*.xml,**/*.properties"/>
<pathconvert pathsep=" " property="assets.flex.output" refid="assets.flex" dirsep="/">
<map from="${basedir}/src/" to=""/>
</pathconvert>
<echo message="...Resources being considered..."/>
<var name="filelist" value=""/>
<var name="prefixfilelist" value="-include-file"/>
<for list="${assets.flex.output}" delimiter=" " param="asset">
<sequential>
<echo>Asset: #{asset}</echo>
<propertyregex property="prop"
input="${asset}"
regexp="(.*)${SRC_DIR}/(.*)"
select="\2"
casesensitive="false"
defaultvalue="./src/"/>
<echo>Prop: ${prop}</echo>
<var name="filelist_tmp" value="${filelist}"/>
<var name="filelist" unset="true"/>
<var name="filelist"
value="${filelist_tmp} ${prefixfilelist} ./#{asset} ${prop}#{asset}"/>
<var name="prop" unset="true"/>
</sequential>
</for>
<echo message="-output ${ASSETS_FILE} ${filelist}"/>
<!-- Windows Compile -->
<exec executable="${FLEX_HOME}/bin/compc.exe"
failonerror="true"
osfamily="winnt">
<arg line="-output ./libs/assets.swc ${filelist}"/>
</exec>
<!-- Unix/Linux Compile -->
<exec executable="${FLEX_HOME}/bin/compc"
failonerror="true"
osfamily="unix">
<arg line="-output ./libs/assets.swc ${filelist}"/>
</exec>
</target>
</project>
We use this approach (which I pieced together from bits and pieces I found on the internet -- I'd gladly give credit if I remembered where) to build a large, module-based project and its embedded images and fonts. There is no reason to think that it wouldn't work for audio files.
Good luck,
Taylor
P.S. There might be some leftover/useless lines of code in there. Also, I'm not an Ant expert, so to any "Ant guys" out there: take it easy on me if I broke any best practices ;)

NAnt and ASP.NET Compiler

I have a build script running successfully, but I am having a hard time running anything after aspnet_compiler completes. I want to use robocopy to copy the project to another folder. If I put the copy task above the compile (as shown below) I get the message to the console, but if I place it after the compile it is not seen. Am I missing something? Do I need to check for a return code from the compiler to call tasks after its completion?
<target name="copy" depends="init">
<echo message="This is my message for robocopy..."/>
</target>
<target name="compile" depends="copy">
<exec program="${msbuild.exe}"
commandline='MySolution.sln /p:Configuration=${Configuration};OutDir="${build.dir}\\"' />
</target>
<target name="precompile-web" depends="compile">
<exec program="${aspnet_compiler.exe}"
commandline='-v /MyProj-p "${build.dir}"\_PublishedWebsites\MyProj.Web'
/>
And yes, when/if I move the copy task below precompile-web I change the depends="precompile-web" and the compile task depends to "init".
If I understand you correctly here, you want to:
Copy the files
Compile them using MSBuild
Precompile them for the web
Is that right? I would have thought you'd want to do it this way around:
Compile the files using MSBuild
Precompile them for the web
Copy the files somewhere else (for use by IIS, etc)
If my way is correct, then I'd guess you'd want your targets to reference each other like this?
<target name="compile-and-publish" depends="compile,precompile-web,copy" />
<target name="compile">
<exec program="${msbuild.exe}" commandline='MySolution.sln /p:Configuration=${Configuration};OutDir="${build.dir}\\"' />
</target>
<target name="precompile-web">
<exec program="${aspnet_compiler.exe}" commandline='-v /MyProj-p "${build.dir}"\_PublishedWebsites\MyProj.Web' />
</target>
<target name="copy" depends="init">
<echo message="This is my message for robocopy..."/>
</target>
This way, you're not pinning each of your targets down to relying upon other targets (for re-use) but you get the order that you need to achieve the job at hand.
Any good to you?

How do I compile an ASP.Net MVC project using MSBuild

How do I compile an ASP.Net MVC project using MSBuild? We use a Continuous Integration server to compile and deploy our applications. To keep things simple I created an MVC 1.0 project in VS2008. I immediately created an MSBuild script file to compile it. I did not change any code in the project. The MSBuild script contained the following target.
<AspNetCompiler
VirtualPath="/"
PhysicalPath="C:\Development\mvc1\"
TargetPath="c:\publish\xxx"
Force="true"
Debug="false"
Updateable="true"
The MVC project sln file is contained in the c:\development\mvc1\ directory. I am running XP/Pro.
I am receiving an error ASPCONFIG: it is an error to use a section registered as allowDefintion='MachineToApplication' beyond application level.. I removed the authenication mode, membership provider, etc. from the web config file until I finally saw a different error message. I am now receiving an error message saying that the file '/views/shared/site.master' does not exist.
What is going on? Thanks in advance for your help!
Am I using the wrong MSBuild command?
If you compile your sln-file (msbuild mysolution.sln) or
<MSBuild Projects="msbuild mysolution.sln" Targets="Rebuild" ContinueOnError="false"
StopOnFirstFailure="false" /><!-- -d -errorstack -->
and the sln-file has the ASP.NET MVC-project .csproj-file then the .csproj-file does have everything you need. Open the .csproj with notepad and look for:
1) This should be true:
<MvcBuildViews>false</MvcBuildViews>
2) Target Name="AfterBuildCompiler":
<Target Name="AfterBuildCompiler" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="SomeVirtualDir" PhysicalPath="C:\Development\mvc1\" TargetPath="c:\publish\xxx\" />
</Target>
I didn't do anything else and it worked. I actually made my config so that only release build deploy the application (by moving MvcBuildViews-property under PropertyGroups. Then I can use the same .csproj in the development (debug) and deployment (release).
This build script compiles an asp.net MVC 3 application. Since the entire internet appears to have forgotten the concept of "Build Script" this one does not require you to have Visual Studio installed on the target Machine or to "lol, you just have to edit your csproj file to get msbuild!!"
Moving on.
Make sure you have .NET 4 and MVC3 installed. By the way, my build scripts only work with msbuild 4, so make sure you're using the proper one.
The general process is as follows (thanks to many hints and answers I got here!)
1) Build the dependencies (you DLL's)
2) Build the DLL for your web application.
3) Call the asp.net compiler task.
4) Check the scripts for additional comments.
Note that this is called from an outside script that compiles other DLL's (Business, data access, etc.)
<Project ToolsVersion="4.0" DefaultTargets="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildDir>..\..\dist</BuildDir>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup >
<Reference Include="System.dll" />
<Reference Include="System.Core.dll" />
<Reference Include="System.Web.Abstractions.dll" />
<!-- add the remaining DLL's required. Check your References folder inside VS2010 and add the relevant entries here. It's a lot of references. I ommited them to make the post more compact.
For reasons that are beyond me, I only managed to get some DLL's referenced by full path. Go figure... -->
<Reference Include="C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Helpers\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.Helpers.dll" />
<Reference Include="C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Mvc\v4.0_3.0.0.0__31bf3856ad364e35\System.Web.Mvc.dll" />
<Reference Include="C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.dll" />
<!-- The "main build script" compiles the other DLL's from the project and places them on the BuildDir folder. Just reference it here-->
<Reference Include="$(BuildDir)\*.dll"></Reference>
</ItemGroup>
<!-- Build a DLL for the code file inside your web project (controllers, models, the lot...) place it together with the other DLL's
WARNING: Simple build command. Resource files are not included in this.
-->
<Target Name="BuildWebDll">
<ItemGroup>
<CodeFiles Include=".\**\*.cs" />
</ItemGroup>
<CSC Sources="#(CodeFiles)" TargetType="Library" References="#(Reference)" OutputAssembly="$(BuildDir)\cth.web.dll" >
</CSC>
</Target>
<!-- For reasons also unkown, but covered in a number os posts in this forum, the asp.net compiler requires the necessary DLL's to be placed on the BIN/ folder of your web project. That's why we're copying every DLL we need to said folder. For debugging, check the Bin folder on Visual Studio after you compile the project. You need to replicate that in your BIN/
-->
<Target Name="CopyDLLs">
<ItemGroup>
<DllFiles Include="$(BuildDir)/*.dll"/>
</ItemGroup>
<Copy SourceFiles="#(DllFiles)" DestinationFolder="Bin\"></Copy>
</Target>
<Target Name="build">
<CallTarget Targets="BuildWebDll"></CallTarget>
<CallTarget Targets="CopyDLLs"></CallTarget>
<!-- Call this from the webproject directory. PhysicalPath references ".". TargetPath can be everything you want -->
<AspNetCompiler Updateable="true" VirtualPath="/CTH.Web" PhysicalPath="./" TargetPath="$(BuildDir)/CTH.Web" Force="true" Debug="false" />
</Target>
Remember that you have to include resource files, do any web.config replacements, etc. I really hope this helps.
The easiest way I found was to add a WebDeployment project to your solution.
http://www.microsoft.com/DOWNLOADS/details.aspx?FamilyID=0aa30ae8-c73b-4bdd-bb1b-fe697256c459&displaylang=en
You set the properties for the build in the WebDeployment project (like precompile ) . The Buildserver builds the wdprj.
In my environment I have to start by building the web first. After that I can start the wdprj.
Here is my nant - script. It should be easy to write the same in msbuild. It actually runs in TeamCity.
xml version="1.0"?>
<project name="GreatProjectWeb"
default="build" basedir="."
xmlns="http://nant.sf.net/release/0.85/nant.xsd">
<description>Build Script</description>
<!-- builds only the csproj, not the entire solution-->
<target name="build" description="Compile the project using Debug configuration for more verbose error descriptions">
<echo message="Building..."> </echo>
<exec program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" >
<arg value="GreatProjectWeb\GreatProjectWeb.csproj" />
<arg value="/t:Build" />
<arg value="/p:Configuration=Release" />
</exec>
<echo message="Building Projektfile finished. Starting WDP Project..."> </echo>
<exec program="C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe" >
<arg value="GreatProjectWeb_Build\GreatProjectWeb_Build.wdproj" />
<arg value="/t:Build" />
<arg value="/p:Configuration=Release" />
</exec>
<exec program="7z" >
<arg value="a" />
<arg value="GreatProjectWeb_Deploy\web_GreatProject.zip" />
<arg value="GreatProjectWeb_Deploy\*" />
</exec>
</target>
</project>
You could use NAnt which has a "msbuild" task in it that will just do it for you. NAnt is a great way to go for CI builds.
The NAnt home page
The NAnt Contrib home page
The MSBuild task reference from NAnt Contrib
...the contrib library adds some great functionality that the vanilla NAnt doesn't have. It is very simple. I've included a snippet of my .build file here so you can see how I've used it:
<property name="DeployDestination" value="\\MyTestServerName\DestinationFolder"/>
<property name="Solution.Configuration" value="Debug" overwrite="True" />
<property name="nant.settings.currentframework" value="net-3.5" />
<if test="${WebContentDestination=='Production'}">
<property name="DeployDestination" value="\\MyProductionServer\DestinationFolder"/>
</if>
...<snip>
<target name="Build">
<msbuild project="SolutionFileName.sln">
<arg value="/p:Configuration=${Solution.Configuration}" />
</msbuild>
</target>
<target name="Deploy">
<copy todir="${DeployDestination}" flatten="true" >
<fileset>All files to copy</fileset>
</copy>
</target>

Custom Flex Ant build task

A beginner's question.
I'm building a .swf with Flex Ant.
To my .swf I link a file, target.as, which I generate from file source.txt with command
./tool.sh source.txt > target.as
How can I add what is described in the above sentence to my ant build process?
The exec task executes any external program:
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
So if you use the mxmlc ant task to compile your swf, you can define your build task like this:
<target name="build">
<exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as">
<arg path="source.txt"/>
</exec>
<mxmlc ....>
...
</mxmlc>
</target>
To run that command in Ant use the exec task.
<exec executable="tool.sh" dir="toolshdir" output="target.as">
<arg value="source.txt" />
</exec>
http://livedocs.adobe.com/flex/3/html/anttasks_1.html
You may also want to use the Flex "mxmlc" task instead of calling it with exec. You can do a lot of configuration right within the XML if you'd prefer not to have to maintain the shell script.

Resources