Compilation Errors with WPF XAML and NuGet `contentFiles` having `buildAction="Compile"`
See original GitHub issueVisual 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:
-
Using Visual Studio, create a new “WPF Library (.NET)”.
-
Add the NuGet package
xunit.assert.source
. (Any NuGet package with such contentFiles will do. This issue has nothing to do with this package.) -
Add some code referencing code from the contentFiles of the NuGet package:
namespace WpfLibrary1 { public class Class1 { Xunit.Sdk.AllException o; } }
-
Compile and note that it compiles.
-
Using Visual Studio, add a “Window (WPF)”.
-
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:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
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
IncludePackageReferencesDuringMarkupCompilation
works for me with .NET 5, thanks! (I didn’t try .NET 6 yet, though.)