1

正如标题所说,我无法让Fody和插件Fody.PropertyChanged在 .NET Core 3.0 或任何 .NET Core 版本中工作。阅读各个 GitHub 页面上的问题并不能回答我的问题,我也无法找到任何相关的答案。

安装后,我无法再运行我的 WPF 项目,并且出现以下错误:

The target process exited without raising a CoreCLR started event.
Ensure that the target process is configured to use .NET Core.
This may be expected if the target process did not run on .NET Core.
The program '[21820] CalculationToolsApp.exe' has exited with code -2147450749 (0x80008083).

有什么建议么?

编辑:我发现我(也许)不能在 FodyWeavers.xml 文件中像这样使用“Fody.Costura”和“Fody.PropertyChanged”:

<Weavers>
  <PropertyChanged />
  <Costura />
</Weavers>

这应该不是问题,因为使用 .NET Core 我无论如何都可以创建单个文件应用程序。从 FodyWeavers.xml 中删除 Costura 引用解决了我的问题!

4

2 回答 2

3

它应该工作。Fody 与 .NET 标准兼容。

  • WPF App (.NET Core)使用Visual Studio 2019 中的模板或使用dotnet new wpf命令创建新的 WPF 应用
  • 安装FodyPropertyChanged.FodyNuGet 包
  • 在项目中添加一个名为“FodyWeavers.xml”的文件,内容如下:

    <Weavers>
        <PropertyChanged />
    </Weavers>
    
  • 建造

如果您随后使用反编译器(例如dotPeek )反编译程序集,您应该会看到预期的注入代码,例如:

public string GivenNames
{
    // Method get_GivenNames with token 06000009
    get
    {
        return this.<GivenNames>k__BackingField;
    }
    // Method set_GivenNames with token 0600000A
    set
    {
        if (string.Equals(this.<GivenNames>k__BackingField, value, StringComparison.Ordinal))
            return;
        this.<GivenNames>k__BackingField = value;
        this.<>OnPropertyChanged(<>PropertyChangedEventArgs.FullName);
        this.<>OnPropertyChanged(<>PropertyChangedEventArgs.GivenNames);
    }
}
于 2019-09-25T12:43:31.667 回答
1

Costura 也没有在 wpf 中使用 .net core 3.1 为我工作。在 .net core 3.1 中,您可以改用它:

  • 构建 -> 发布 -> 创建配置文件 -> 编辑“配置”
  • 目标运行时 = win-x64(或您想要的任何目标系统,但不是“便携式”)
  • 展开“文件发布选项”
  • 检查:生成单个文件
  • 节省

当您现在选择构建 -> 发布 -> 发布按钮时,它将创建单个文件。

似乎是因为 .net 核心的“单文件可执行文件”功能,他们停止了 costura 项目。尽管此功能仍然落后于 costura,因为您必须设置目标运行时。

https://github.com/Fody/Costura/issues/442

在 dotnet core 3 中有两个新特性

Single-file executables
Assembly linking

由于 dotnet 工具集中包含这些功能,Costura 的价值主张大大降低。考虑到这一点,我认为随着人们过渡,应该停止使用长期的 Costura。

请评论任何输入。

计划:

disable issues
PR will still be accepted but only for bug fixes
add note to readme
add note to nuget description
write a warning in 

.NET 5 的更新:
对于 .NET 5 和当前的 Visual Studio 版本 16.10.2,向导发生了变化。尽管我检查了单个文件等的选项,但我无法再使用向导了。但是使用控制台有效:工具->命令行->开发人员命令提示符->输入:

dotnet publish -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeAllContentForSelfExtract=true

.NET 5 未编译为单个文件可执行文件

于 2020-02-09T18:01:40.987 回答