question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compilation Errors with WPF XAML and NuGet `contentFiles` having `buildAction="Compile"`

See original GitHub issue

Visual Studio Version: 16.8.6

Summary: I’m getting compilation errors with the combination of XAML files and NuGet packages with contentFiles with buildAction="Compile".

I’m not sure if this is the right place to address this.

It seems to me this happens as soon as there is some XAML file with non-trivial content, and that this happens in “WPF Libraries” and “WPF Apps”. The code in the contentFiles from the NuGet package(s) actually gets compiled and is included in the resulting assembly, however referencing it always gives me an error.

Steps to Reproduce:

  1. Using Visual Studio, create a new “WPF Library (.NET)”.

  2. Add the NuGet package xunit.assert.source. (Any NuGet package with such contentFiles will do. This issue has nothing to do with this package.)

  3. Add some code referencing code from the contentFiles of the NuGet package:

    namespace WpfLibrary1
    {
        public class Class1
        {
            Xunit.Sdk.AllException o;
        }
    }
    
  4. Compile and note that it compiles.

  5. Using Visual Studio, add a “Window (WPF)”.

  6. Compile using Visual Studio or dotnet build.

Expected Behavior: Compiles without errors.

Actual Behavior: Compilation error:

C:.…\WpfLibrary1\Class1.cs(5,7): error CS0246: The type or namespace name ‘Xunit’ could not be found (are you missing a using directive or an assembly reference?) [C:.…\WpfLibrary1\WpfLibrary1_nju0xbui_wpftmp.csproj]

User Impact: Users cannot use NuGet packages containing contentFiles with buildAction="Compile" with projects that contain a WPF XAML file.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Aug 20, 2021

I believe that this is fixed in the .NET 6 SDK, and you can opt in to a fix (which may still have some issues) in the .NET 5 SDK by setting IncludePackageReferencesDuringMarkupCompilation to true.

@ryalanms @dotnet/wpf-developers

0reactions
Molinariuscommented, Aug 25, 2021

IncludePackageReferencesDuringMarkupCompilation works for me with .NET 5, thanks! (I didn’t try .NET 6 yet, though.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Contentfile in nuget gets compiled causing build errors
When installing the nuget in a regular wpf app, I get a couple build errors. It appears that Visual Studio is trying to...
Read more >
Build actions for files - Visual Studio (Windows)
All files in a Visual Studio project have a build action. The build action controls what happens to the file when the project...
Read more >
Installing UI for WPF from a NuGet package - Documentation
This article describes how to use the telerik NuGet server or setup a local package source to download UI for WPF dlls from...
Read more >
PDF | Xamarin | Mobile App
Installing NUnit 2.6.4 using NuGet. Multi Process Debugging Desktop Developers App lifecycle comparison. UI controls comparison. WPF vs Xamarin.Forms
Read more >
Vs 2017 Xamarin | PDF | Mac OS | Android (sistema ...
Windows apps (WinForms, WPF, or UWP) are built with Visual Studio. They do not use Xamarin directly. However, C# code can be shared...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found