开发者

Referenced library isn't copied

开发者 https://www.devze.com 2023-04-03 04:54 出处:网络
I have ProjectA(WPFApplication) that references ProjectB(ClassLibrary). Inside ProjectB i have wpf window that uses control from ThirdParty.dll wich i accordingly reference from ProjectB.

I have ProjectA(WPFApplication) that references ProjectB(ClassLibrary). Inside ProjectB i have wpf window that uses control from ThirdParty.dll wich i accordingly reference from ProjectB.

The problem is that it doesn't find ThirdParty.dll in output folder of ProjectA and xaml parse runtime exceprion is raised. There is no ThirdParty.dll in GAC. Copy Locally is set to true. It works if i manually add in output folder of ProjectA that library 开发者_Go百科and it also works if i use that ThirdParty.dll somwhere right in my cs files.

How can i solve that?


The reason for this is that visual studio only copies resources to the output folder if Copy Local is set. Just set the reference to Copy Local and you should be fine.

Check out this link on how this works.

When you reference ProjectA, the references from ProjectB is not automatically referenced. For this to work, you need to add a reference to ThirdParty.dll from ProjectA as well if you only use it in XAML. The compiler does not copy references that are only used in XAML. But if you use them in code, they are copied.

This is the same issue as discussed here


You should add the reference to the thrid party dll to the project where you want it to appear in the output directory. If the Copy Local is then set to true it will appear in you bin directory whether or not you use it in code or xaml.


Add something like this to ProjectB.csproj:

<ItemGroup>
   <Content Include="...\path\ThirdParty.dll">
      <Link>ThirdParty.dll</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
   </Content>
</ItemGroup>

This convinces VS to copy ThirdParty.dll to the output folder of ProjectA, too (no need to add anything to ProjectA about ThirdParty.dll).
I still find it inadequate because if ThirdParty.dll is in a NuGet package, its path usually contains version number, which will change when you update the package.
I haven't tried it yet but I don't expect from NuGet to update the path here as it does in <Reference>.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号