我目前有 2 个项目,一个是标准的 ASMX Web 服务,另一个是测试项目。Web 服务项目有一个Web.config
文件,其中包含我的连接字符串。我知道如何将连接字符串更改为 qa 或生产。我的问题是我不确定如何更改我的测试项目的连接字符串。我想要的是使用 SQLite 进行测试。
这是我添加到测试 .csproj 文件中的目标文件的样子。
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ConnectionString>Data Source=:memory:</ConnectionString>
</PropertyGroup>
<Target Name="BeforeBuild"
DependsOnTargets="Clean" />
<Target Name="AfterBuild"
DependsOnTargets="UpdateConfigFileForEnvironment" />
<Target Name="UpdateConfigFileForEnvironment">
<PropertyGroup>
<AppConfigFileName>$(OutDir)Web.config</AppConfigFileName>
</PropertyGroup>
<FileUpdate
Files="$(AppConfigFileName)"
Encoding="ASCII"
Regex="ConnectionStringBuild"
ReplacementText="$(ConnectionString)" />
</Target>
</Project>
这是Web.config
Web 服务项目中的文件。我省略了大部分内容,因为它无关紧要。
<appSettings>
<add key="ConnectionString" value="ConnectionStringBuild" />
</appSettings>
当我在 VS2008 中通过 ReSharper 运行单元测试时,没有返回任何AppSettings
条目的问题。ConnectionString
此外,如果我msbuild
在测试项目的命令行中运行,则连接字符串会成功更新。
运行测试时如何修改连接字符串?