我试图在我的WPF项目上第一次使用材料设计,我从nuget安装包,但当我试图运行它时,它提示:
System.Windows.Markup。XamlParseException:无法加载文件或MaterialDesignThemes大会"。Wpf、文化=中立,都必须df2a72020bd7962a"。系统找不到文件指定。">
当我手动复制程序集到输出文件夹时,它的工作。
我.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<BaseOutputPath>$(SolutionDir)bin</BaseOutputPath>
<OutputPath>$(SolutionDir)bin</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="4.6.1" />
<PackageReference Include="ShowMeTheXAML.MSBuild" Version="2.0.0" />
</ItemGroup>
</Project>
我试着添加
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
但是它什么也没做。
这一行会导致visual studio忽略程序集的复制:
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
:
github.com dotnet sdk - UseCommonOutputDirectory=true打破CopyLocalLockFileAssemblies标志#23342
Microsoft - build-to- common-output-directory
这是我的。csproj
<Project Sdk="Microsoft.NET. Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MaterialDesignThemes" Version="4.6.1" />
</ItemGroup>
</Project>
自动复制是好的。你的问题没有发生。您是否尝试重新创建项目,是否会出现相同的问题?
如果仍然不起作用,您可能需要添加msbuild事件来复制文件。使用xcopy。