silverlight-host

用过Silverlight的兄弟都清楚,当在Visual Studio 2008中建立一个Silverlight Application Project时,首先会弹出一个提示框如上图,询问是否自动生成一个ASP.NET网站来托管这个Silverlight应用。默认会建立。一般情况下我们都会选择不建立,这样会在解决方案里少生成一个项目。
自动生成一个ASP.NET网站来托管这个Silverlight应用的好处是,在每次Debug整个解决方案的时候,Visual Studio 2008会自动首先编译Silverlight项目,然后把编译结果,一个xap文件,自动拷贝到ASP.NET网站项目的ClientBin下,然后启动ASP.NET网站项目的默认页面,显示了最新版本的Silverlight应用。如下图所示。

silverlight-host2

问题是,如果你一开始没有让Visual Studio 2008建立那个网站项目,如果哪天你需要一个网站了,可能是各种原因,比如需要一个本地的Web Service等等,自己新建一个ASP.NET网站,就不能实现上面的自动拷贝xap文件了。

解决方法比较绕。这是一个MSBuild问题,你需要Unload各个项目,然后用写字板打开ASP.NET的项目文件(csproj文件),然后在PropertyGroup中加一个SilverlightApplicationList项,如图:

silverlight-host3

注意相对路径,项目名称以及项目的GUID。这些东西都可以在解决方案文件(sln文件)里找到。就不详细解释了。

silverlight-host4

Reload项目之后Build,就会发现你的项目可以自动把xap文件拷贝到ClientBin下了。

后记:作为一个使用Silverlight开发了无数年的工程师,这似乎是我第一次写关于Silverlight的博文。现在想想,大概是公司政策使然?我应该是个很守规矩的人。

c-sharp-comment

public sealed class ScrollViewer : ContentControl

[code=’csharp’]
//
// Summary:
// Gets a value that represents the horizontal size of the area that can be
// scrolled; the difference between the width of the extent and the width of
// the viewport..
//
// Returns:
// The horizontal size of the area that can be scrolled. This property has no
// default value.
public double ScrollableWidth { get; internal set; }
[/code]

Silverlight Control里面的小细节,小小小细节…
好几篇这样的文章了,以后学着粗枝大叶一点,产品中的这些小细节太让我恼火了。

补充几句,觉得C#里面的注释写得太像八股文了。最近写了好多好多,现在随便开个东西开始无意识输出的是“Gets or sets a value indicating whether…”。