How to have XAP against every module

Topics: Prism v2 - Silverlight 4
Jan 8, 2011 at 2:04 PM

Hi all,
I'm using PRISM 2 along with SL4. Lately I've been trying to implement OnDemand module loading using PRISM.The need for doing this is, size of my XAP, which is loaded all at once. So I thought of breaking up the XAP file module wise.

But my problem is that I'm not using XAML for module configuration rather I'm doing it through code. My first question is that: am I supposed to have this line of code always out of the project i.e MyModule is the name of my project in this case.

moduleManager.LoadModule("MyModule");


 

Having said that I'm also facing problem while splitting the XAP file. for that I found the following link, this is the only usable link I've found so far.

http://jomit.blogspot.com/2009/06/loading-xap-files-ondemand-using.html

As there you can see that guy is referencing to the multiple XAP files to the website but I'm unable to view any other silverlight project on my website rather I see my Shell under that window. To cut it short what is the way to configure the XAP so that every client silverlight project has its own XAP that is set to be downloaded to the browser on demand.

 

Any sort of help is most welcome.

 

regards,

Jan 8, 2011 at 4:02 PM

I dont quite understand your question. But to have a xap for each module amounts to adding that many silverlight applications to your solution. When you build a silverlight application it creates tha xap for it and adds it to the ClientBin folder.

Jan 10, 2011 at 6:24 AM

Hi,
sorry for being unclear. All I want to know is how to to have multiple XAP files in the client bin? I've multiple silverlight projects [on the client side of the PRISM solution structure] but my shell silverlight project is the only thing that generates the XAP file [i.e single xap file is being generated] in the ClientBin on the server. I want to have multiple i.e. XAP against every silverlight project. MEF offers such thing but I don't want to use that.

 

I've implemented modularity to my client side and my modules are loaded onDemand. If someone can guide me what to do next in PRISM for the above problem.

 

regards,

 

 

Developer
Jan 10, 2011 at 1:47 PM
Edited Jan 12, 2011 at 1:48 PM

Hi,

The Silverlight Class Library template does not output a xap file by default. You could create your modules using the Silverlight Application template, which does create a xap file, or manually edit the .csproj file and add the following XML nodes in the same property group that specifies the <ProjectGuid> tag:

    <XapOutputs>true</XapOutputs>
    <XapFilename>YourModule.xap</XapFilename>

You can read more about modularity in this chapter from the Prism MSDN documentation. Also, you can find the Modularity QuickStarts useful to learn more about this scenario.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

 

Jan 10, 2011 at 2:10 PM

Hi again,
I've been searching for the same and found out that Silverlight Class Library template produces the dll whereas the Project template generates XAP by default. Actually my original problem was how not to download XAP at once instead dynamically load dll/XAP. I'm trying to avoid fat XAP.

 

Any thoughts on that ?

 

Developer
Jan 10, 2011 at 2:59 PM
Edited Jan 10, 2011 at 3:00 PM

Hi again,

You can download your modules in the background on demand, as explained in the "Downloading Remote Modules in the Background" section of the aforementioned chapter. You can also find an example of downloading modules in the background in the QuickStarts.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Jan 12, 2011 at 11:58 AM

Hi, I tried adding the following lines as you mentioned but sadly this doesn't generate XAP either.

<XapOutputs>true</XapOutputs>
<XapFilename>ModuleF.xap</XapFilename>

So, Now I think Silverlight Application Project Template seems to be the only answer to my problem. However reason we use Silverlight Class Library template instead, was that it enable us to choose among RIA services projects from the server side under "WCF RIA Services link". Whereas the silverlight application template is only limited to the RIA services present in the Host Website only i.e. it doesn't show any other server project to link with, under "WCF RIA services link" other than host Website. 

I know it's something irrelevant to this forum but I'll be really thankful if I can get your say on that.

Also, I did get your "Downloading Remote Modules in the Background" section and also the quickstart but my problem is that I'm using PRISM 2.2 should it work in my case or do I need to upgrade to Prism 4?

 

 

  
Developer
Jan 12, 2011 at 2:11 PM
Edited Jan 12, 2011 at 2:13 PM

Hi,

The lines I've mentioned have to be added into the property group that includes the <ProjectGuid> tag, which in the case of Silverlight Class Libraries is the second PropertyGroup, not the first one. I'm sorry for the inconveniences. To illustrate this, I'll include parts of the the csproj for the HelloWorldModule in the HelloWorld QuickStart, where I added the XapOutputs and XapFilename tags:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(MSBuildToolsVersion)' == '3.5'">
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>9.0.30729</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{B2CC15D4-9293-4164-B4AC-A3622D5952D0}</ProjectGuid>
    <ProjectTypeGuids>{A1591282-1198-4647-A2B1-27E5FF5F6F3B};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>HelloWorldModule</RootNamespace>
    <AssemblyName>HelloWorldModule</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <SilverlightApplication>false</SilverlightApplication>
    <ValidateXaml>true</ValidateXaml>
    <ThrowErrorsInValidation>false</ThrowErrorsInValidation>
    <FileUpgradeFlags></FileUpgradeFlags>
    <OldToolsVersion>3.5</OldToolsVersion>
    <UpgradeBackupLocation></UpgradeBackupLocation>
    <TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
    <SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
    <PublishUrl>publish\</PublishUrl>
    <Install>true</Install>
    <InstallFrom>Disk</InstallFrom>
    <UpdateEnabled>false</UpdateEnabled>
    <UpdateMode>Foreground</UpdateMode>
    <UpdateInterval>7</UpdateInterval>
    <UpdateIntervalUnits>Days</UpdateIntervalUnits>
    <UpdatePeriodically>false</UpdatePeriodically>
    <UpdateRequired>false</UpdateRequired>
    <MapFileExtensions>true</MapFileExtensions>
    <ApplicationRevision>0</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    <IsWebBootstrapper>false</IsWebBootstrapper>
    <UseApplicationTrust>false</UseApplicationTrust>
    <BootstrapperEnabled>true</BootstrapperEnabled>
    <TargetFrameworkProfile />
    <XapOutputs>true</XapOutputs>
    <XapFilename>HelloWorld.xap</XapFilename>

</PropertyGroup>
(...)
</Project>

As for what you're mentioning about not being able to create a WCF RIA Services link between a Silverlight Application and another Web site that isn't the one that hosts it, I wasn't able to reproduce it. You could try unchecking the Host the Silverlight application in a new or existing Web site in the solution option when creating your Silverlight Application, and then trying to add a WCF RIA Services link to any of the existing Web sites. If you continue experiencing problems with that, it could be helpful if you could provide us with further details about your project structure, so we can help you out. However, you should be able to achieve your requirement with the Silverlight Class library.

On a different note, you can also achieve remote module downloading in Prism 2.2. You can find the following articles useful to that purpose:

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Jan 13, 2011 at 7:54 AM

Hi again,

Thanks for pointing out the issue. I did manage to generate another XAP for my silverlight class library project template. I did update

<SilverlightApplication>false</SilverlightApplication> to    

<SilverlightApplication>true</SilverlightApplication>

And I've also implemented modularity through code where I'm loading one module set as onDemand and other module as WhenAvailable and there I'm loading these modules through my code again rather using XAML modulecatalog. For that I'm using Module references into my bootsrapper i.e shell project. Now the thing is, I've multiple XAP being generated in the client bin e.g. one XAP is for my shell project another let's say Module A that is set to WhenAvailable and Module B that is configured to OnDemand and I'm further loading this module through my code. Now when I open my shell XAP to see the dlls inside it, I also see dll of my Module A and Module B along within my shell XAPs, not to mention the Module A and Module B XAPs. My app runs just fine unless i try to set "Copy Local" to false for the references to Module A and Module B in my shell project. 

All I'm trying to say is that although I have different XAPs inside my ClientBin and I've implemented remote module downlading in Prism without catalogmodule xaml i.e. through code. but I think, still only Shell XAP is what's running my application.

I hope I conveyed my point.

 

regards,

 

Developer
Jan 13, 2011 at 1:54 PM
Edited Jan 13, 2011 at 2:17 PM

Hi,

The problem you're experiencing might be because you're specifying a relative path for your modules when you declare the remote loading of them, so when you don't add the reference to a module in the shell project, the XapModuleTypeLoader can't find it.

In case you keep experiencing this behavior, it could be useful if you could provide us with more information regarding the exception you're being thrown, the way you're implementing remote module downloading and if it is possible a repro sample, so that we can help you further.

I hope you find this helpful.

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Developer
Jan 13, 2011 at 1:58 PM

Hi,

I've read your new thread, in which you provide the information I'm requesting here, so let's continue the discussion there.

Thanks,

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi

Jan 14, 2011 at 10:48 AM

hi ,

can you tell me how can i send you my sample?

Developer
Jan 14, 2011 at 3:31 PM

Hi,

In case the suggestions in your other thread didn't help you solve your issue, you could upload your sample to a site like SkyDrive and post the link to it here.

Thanks,

Guido Leandro Maliandi
http://blogs.southworks.net/gmaliandi