您的位置:首页 > 其它

Silverlight 2学习教程(四):Chiron.exe:Silverlight 2打包和动态语言部署工具

2009-02-17 14:33 387 查看
VS在编译时Silverlight 2的应用程序时,会先将cs等文件进行编译成dll,然后会调用Chiron.exe这个打包工具打包成.xap文件。也可以使用它进行动态语言无打包部署。Chiron.exe一般位于C:/Program Files/Microsoft SDKs/Silverlight/v2.0/Tools/Chiron文件夹下,.xap格式的文件其实就是一个zip格式的压缩包,如果将扩展名改为.zip,可以使用解压缩工具进行解压。解压后的文件可以使用Chiron这个工具再进行打包成.xap文件。

例如:将E:/Example1/Mengxianhui/ClientBin/SilverlightApplication1下的文件打包成SilverlightApplication1.xap,命令如下:

Chiron.exe /d: E:/Example1/Mengxianhui/ClientBin/SilverlightApplication1 /x: SilverlightApplication1.xap

对于动态语言,如IronRuby、IronPython和Managed JScript,除了可以进行打包之外,还可以进行直接部署。
例如:有这样的文件夹结构:

E:/SilverLight2Example/Example2/default.htm
E:/SilverLight2Example/Example2/app/app.xaml
E:/SilverLight2Example/Example2/app/app.jsx

其中:
default.htm的内容是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>动态 Silverlight 测试页面</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightControlHost {
height: 100%;
}
</style>

<script type="text/javascript">
function onSilverlightError(sender, args) {
if (args.errorType == "InitializeError") {
var errorDiv = document.getElementById("errorLocation");
if (errorDiv != null)
errorDiv.innerHTML = args.errorType + "- " + args.errorMessage;
}
}
</script>
</head>
<body>
<div id='errorLocation' style="font-size: small;color: Gray;"></div>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight," type="application/x-silverlight-2-b1" width="100%" height="100%">
<param name="source" value="app.xap"/>
<param name="onerror" value="onSilverlightError" />
<param name="background" value="white" />
<param name="initParams" value="debug=true,reportErrors=errorLocation" />
<param name="windowless" value="true" />

<a href="http://go.microsoft.com/fwlink/?LinkID=108182" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>
</a>
</object>
<iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe>
</div>
</body>
</html>

app.xaml:

<UserControl xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="System.Windows.Controls.UserControl"
x:Name="Page"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Canvas Canvas.Top="20">
<TextBlock Canvas.Top="10" Canvas.Left="20">请输入您的姓名: </TextBlock>
<TextBox x:Name="UserInput" Width="200" Height="30" Canvas.Top="40" Canvas.Left="20"></TextBox>
<TextBlock x:Name="Msg" Canvas.Top="90" Canvas.Left="20" Foreground="Navy" FontSize="48" ></TextBlock>
</Canvas>
</Grid>
</UserControl>

app.jsx:

Import("System.Windows.Application")
Import("System.Windows.Controls.*")
Import("System.Windows.*")

var xaml;
function App() {
xaml = Application.Current.LoadRootVisual(new UserControl(), "app.xaml")
}

App.prototype.start = function() {
//注册事件处理器
xaml.UserInput.KeyUp += handler1;
}

function handler1(sender, args) {
xaml.Msg.Text = "Hello," + xaml.UserInput.Text;
}

app = new App
app.start()

则先切换到E:/SilverLight2Example/Example2文件夹,然后执行:

E:/SilverLight2Example/Example2>"C:/Program Files/Microsoft SDKs/Silverlight/v2.0/Tools/Chiron/Chiron.exe" /w

Chiron就会启动一个http的Web服务器,将E:/SilverLight2Example/Example2/作为网站的根目录

单击“default.htm”文件

比较奇怪的是:
1,app.xaml里居然不能写<Button></Button>对象,不知道是何原因;
2,输入框不支持中文,汗啊;
3,这个工具不稳定,老是将浏览器搞掉。

Chiron的完整参数列表:
用法: Chiron [<选项>]


通用选项:

/d[irectory]:<path>
指定文件夹(默认是当前文件夹)
/x[ap]:<file>
指定要产生的XAP文件名
没有启动Web服务器,不能与/w或/b组合使用

/n[ologo]
忽略logo的显示

/s[ilent]
忽略所有输出的显示

动态语言选项:

/z[ipdlr]:<file>
与/x相同,但包含动态语言程序所需要的文件
不启动web服务器,不能与/w或者/b同时使用

/w[ebserver][:<port number>]
启动一个web服务器,自动为动态语言应用程序创建XAP文件,端口可选,默认是2060

/b[rowser]
启动系统当前默认的浏览器,并启动Web服务器。
含义与/w相同,但不能与/x或者/z组合使用

/r[efpath]:<path>
指定包含动态语言装配件的文件夹
只拷贝项目中程序语言使用的装配件,默认是Chrion安装目录下的dlr子文件夹

/m[anifest]
将生成的AppManifest.xaml文件保存到磁盘上,使用/d设置包含资源的文件夹,只能与/d、/n和/s组合使用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: