how to change the location that the references dll

2019-03-01 11:22发布

i am using some libraries and i added a reference to that library dll and i set the "Copy Local" to true.
but i want to change the location of the dll to be a subfolder in the exe folder and not with the exe.
how is this possible?
thanks

Update:
i used the following Post-build event [as Jon Skeet recommended]

move /y $(TargetDir)\System.Data.SqlServerCe.dll   $(TargetDir)\Lib\SqlSrvCe\System.Data.SqlServerCe.dll

3条回答
ら.Afraid
2楼-- · 2019-03-01 11:34

Do you need it as a reference? Or is the reference only to copy the dll to the desired location?

If you do not need the reference, try adding it to the project and setting it to always copy.

Add the dll to a folder in the project and set to Copy to Output Directory http://web11.twitpic.com/img/146848312-ecfdeadf5b322fe755c7a764d6e6dbf0.4c69c2f0-full.png

查看更多
姐就是有狂的资本
3楼-- · 2019-03-01 11:40

I don't know whether it's feasible within "normal" build rules, but you could add post-build steps which basically moved the files. It would be ugly, but it should work.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-01 11:54

You'll need a .config file for your .exe so that the probing path is changed. A subdirectory is no problem, just use the <probing> element, its privatePath attribute is a relative folder name.

Beware however that you'll get little help from the IDE to put the DLL in that spot. You'll need a post build event that creates the folder if necessary and xcopy's the DLL there. Something like this:

if not exist "$(TargetDir)mumble" mkdir "$(TargetDir)mumble"
xcopy /d /y "$(TargetDir)something.dll" "$(TargetDir)mumble"
查看更多
登录 后发表回答