简体   繁体   中英

Nuget package dependency between projects when package used in XAML only

I have C# WPF application solution with Windows Application and a Class Library DLL that implements some of the views and viewmodels. I added the Extended.Wpf.Toolkit package to the DLL project and use a control in that package from the XAML in my DLL project. The executable project references the DLL project. When I build, there are no DLLs from the package copied to the executable project bin/Debug folder (they are of course in the bin/Debug of the DLL project).

The DLL project uses some other packages and DLLs of these appear in executable bin/Debug folder automagically. The only difference in case of Extended.Wpf.Toolkit is that I have no codebehind using anything from this package.

I tried adding some dummy code to the DLL project using random class from the Extended.Wpf.Toolkit and then one of the DLLs appeared in bin. So apparently the Visual Studio now acknowledges the dependency to some extent (it copies one DLL only though).

The XAML in DLL project:

<UserControl x:Class="MyNameSpace.PropertyPanel"
    ...
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    >
    <Grid>
        <xctk:PropertyGrid/>
    </Grid>
</UserControl>

So apparently I need to add the nuget package to the executable project too? Why is there a difference between using the package from XAML vs codebehind?

Using Visual Studio 2017 Community edition, if that matters. The nuget packages.config is located in class library project:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Extended.Wpf.Toolkit" version="3.6.0" targetFramework="net452" />
  <package id="SharpVectors.Reloaded" version="1.3.0" targetFramework="net452" />
</packages>

Sorry for the lack of simple replicatable project.

Why is there a difference between using the package from XAML vs codebehind?

This is a known XAML issue. The compiler doesn't copy references that are only used in XAML.

The workaround is easy. Set the Copy Local property for the assembly to True in the class library project install the NuGet package in the consuming WPF application project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM