“构建”时的问题引用另一个项目的 WCF REST 服务
我有一个包含两个项目的解决方案:
- DataAccessLayer 项目 - 一个不言自明的类库,它引用 .NET MySql 连接器 dll,并能够将其设置保存到设置文件 .
- WebService 项目 - 具有 WCF REST 服务,该服务具有对 DataAccessLayer 项目的引用。
构建“WebService”项目(在“发布”模式下)后,我无法在“WebService”发布文件夹中找到 DataAccessLayer.dll.config 文件和 MySql.Data.dll 文件。
更新: 好吧,经过一些实验,我发现在“DataAccessLayer”项目中将“MySql.Data.dll”引用的“Copy Local”属性设置为 true,将其复制到构建时的 DataAccessLayer“发布文件夹”。但是,在构建“WebService”项目时,我在“WebService”的 bin\Release 文件夹中看到的唯一文件是“DataAccessLayer.dll”文件、“WebService.dll”文件及其相对的“.pdb”文件。 (仍然没有 MySql.Data.dll 和 DataAccessLayer.dll.config)。
更新2: 好吧,不确定是否有更优雅或更好的解决方案,但我最终向“WebService”项目添加了“Post-Build”事件(项目属性 -> Build Events),该项目从“DataAccessLayer”输出复制两个文件目录到“WebService”输出目录,按以下方式:
copy "$(SolutionDir)DataAccessLayer\bin\$(ConfigurationName)\MySql.Data.dll" "$(TargetDir)" &
copy "$(SolutionDir)DataAccessLayer\bin\$(ConfigurationName)\DataAccessLayer.dll.config" "$(TargetDir)"
如果有人想到更通用的方法来执行此操作,请告诉我!
谢谢,
麦基
I have a solution with two projects:
- DataAccessLayer project - A self explanatory class library, which has a reference to .NET MySql connector dlls and able to save it's settings to a Settings file, .
- WebService project - has the WCF REST service which has a reference to the DataAccessLayer project.
After I build the "WebService" project (in 'Release' mode) I cannot locate both the DataAccessLayer.dll.config file and MySql.Data.dll file in the "WebService" Release folder.
UPDATE:
Well, after some experimenting I figured that setting "MySql.Data.dll" reference's "Copy Local" property to true in the "DataAccessLayer" project, copies it to the DataAccessLayer "Release Folder" on build. But still, when building the "WebService" project - the only files I see in the "WebService"'s bin\Release folder are the "DataAccessLayer.dll" file, the "WebService.dll" file and their relative ".pdb" files. (still no MySql.Data.dll and DataAccessLayer.dll.config).
UPDATE 2:
Ok, not sure there's a more elegant or better solution but I ended up adding a "Post-Build" event (Project Properties -> Build Events) to the "WebService" project, which copies the two files from the "DataAccessLayer" output directory to the "WebService" output directory, in the following manner:
copy "$(SolutionDir)DataAccessLayer\bin\$(ConfigurationName)\MySql.Data.dll" "$(TargetDir)" &
copy "$(SolutionDir)DataAccessLayer\bin\$(ConfigurationName)\DataAccessLayer.dll.config" "$(TargetDir)"
If anyone thinks of a more generic way of doing this, please let me know!
Thanks,
Mikey
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设 MySQL.Data.dll 被 DataAccessLayer 项目引用。如果是这种情况,请转到参考并打开其属性。应该有一个选项显示“复制本地”,仔细检查它是否设置为 true(我认为它默认为 false)。如果这不是问题,您也可以尝试引用 WebService 项目中的 dll,这应该将其复制过来。或者您可以将 DLL 添加到 GAC,或者最坏的情况是,您始终可以手动复制文件(只要它位于 bin 目录中,它就应该找到它),但从长远来看,这会很糟糕。
I'm assuming that the MySQL.Data.dll is referenced by the DataAccessLayer project. If that's the case, go to the reference and open up its properties. There should be an option that says Copy Local, double check that it's set to true (I think it defaults to false). And if that isn't the issue, you can try referencing the dll in the WebService project also, which should copy it over. Or you could add the DLL to the GAC or, worst case scenario, you can always just copy the files over manually (as long as it's in the bin directory, it should find it), but that would suck long term.