deerchao的blog

Be and aware of who you are.

导航

统计

公告

发布网站时自动切换connectionString

1,安装 Web Deploy Projects
2,在VS里右击Web项目, Add Web Deployment Project, 确定
3,设置新添加的项目的属性. 其中的"Compilation"页中 Output Path即为要发布到的目录.
4,在项目属性的Deployment页中,选中"Enable Web.config file section replacement",在下面输入"connectionStrings=connectionStrings.config;",确定
5,在原来的Web项目中添加一个connectionStrings.config文件,在里面输入发布版/生产环境版的connectionStrings:

<connectionStrings>
    
<add  />
</connectionStrings>

6,原来的Web项目里的web.config文件里,connectionStrings节里只需要包含开发时用到的连接字符串.
7,要发布时,执行一下deployment项目的"生成"操作,即可从自己设置的Output Path里找到可以直接发布的文件和目录结构了

另,如果一些文件不希望发布(比如文件file1.name和file2.name,目录dir1.name和dir2.name ),可以打开deployment项目的项目文件,通过下面的修改来实现:
  <ItemGroup>
    
<RemoveFileAfterBuild Include="$(OutputPath)\file1.name"/>
    
<RemoveFileAfterBuild  Include="$(OutputPath)\file2.name"/>
    
<RemoveDirAfterBuild  Include="$(OutputPath)\dir1.name"/>
    
<RemoveDirAfterBuild  Include="$(OutputPath)\dir2.name"/>
  
</ItemGroup>

  
<Target Name="AfterBuild">
    
<RemoveDir Directories="@(RemoveDirAfterBuild)" />
    
<Delete Files="@(RemoveFileAfterBuild)" />
  
</Target>

posted on 2008-06-22 00:34 deerchao 阅读(201) 评论(0) 编辑 收藏