使用NAnt构建Windows应用时遇SqlServerCe.RepairOption成员缺失错误求助
Let’s walk through the key troubleshooting steps to resolve this mismatch between your Visual Studio 2013 environment and NAnt’s build process. Since VS isn’t flagging the error but NAnt is, the root cause almost always relates to version or environment inconsistencies.
Verify SQL Server Compact Edition version mismatch
TheRecoverAllPossibleRowsmember ofRepairOptionwas introduced in specific versions of SQL Server Compact (likely 4.0 or later). First, check the version ofSystem.Data.SqlServerCe.dllyour project references in VS: right-click the reference → Properties → note the "Version" field. Then, check which version NAnt loads during the build—look for assembly loading logs in the NAnt output, or add a temporary debug step to print the assembly path/version. If NAnt pulls an older version (e.g., from the GAC or a different directory), that’s the issue.Align NAnt’s .NET Framework target with your project
Visual Studio might target a specific .NET Framework version (e.g., 4.0), but NAnt could default to an older runtime. Open your NAnt build script and explicitly set the target framework to match your project:<project name="YourApp" default="rebuild" framework="net-4.0">You can also check the
nant.exe.configfile to confirm default framework settings haven’t been overridden.Force NAnt to use your project’s local assembly reference
NAnt might prioritize a version ofSystem.Data.SqlServerCe.dllfrom the Global Assembly Cache (GAC) instead of your project’s local copy. Fix this by explicitly specifying the assembly path in your NAnt build target:<csc target="exe" output="bin/YourApp.exe"> <sources> <include name="**/*.cs" /> </sources> <references> <include name="path/to/your/project/References/System.Data.SqlServerCe.dll" /> <!-- Add other project references here --> </references> </csc>This ensures NAnt uses the exact same DLL Visual Studio relies on.
Clean all build artifacts thoroughly
Stale build files in NAnt’s output or intermediate folders can cause version conflicts. Run a full manual clean: delete NAnt’sbin/objdirectories, clear cached assemblies, then re-run the rebuild command. Ensure your NAntrebuildtarget explicitly deletes these folders before starting the build.Validate the enum exists in your referenced assembly
Double-check thatRecoverAllPossibleRowsis present in your project’sSystem.Data.SqlServerCe.dll. Use a tool like ILSpy or dotPeek to open the DLL and inspect theSystem.Data.SqlServerCe.RepairOptionenum. If it’s missing, you might have accidentally referenced an older assembly version (even if VS didn’t flag it).
内容的提问来源于stack exchange,提问作者Ernesto Jorge

