简体   繁体   中英

Can Fody and its plugins be used with .NET Core (3.0)?

As the title says, I'm having trouble getting Fody , and the plugin Fody.PropertyChanged , to work in .NET Core 3.0, or any .NET Core version. Reading the issues on the respective GitHub pages doesn't answer my question, nor am I able to find any relevant answers.

Once installed I cannot run my WPF project anymore and I am given the following error:

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).

Any suggestions?

EDIT: I found out that I (maybe) cant use "Fody.Costura" with "Fody.PropertyChanged" like this in the FodyWeavers.xml file:

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

Which shouldn't be a problem because with .NET Core I can create a single file application anyway. Removing the Costura reference from the FodyWeavers.xml solved my problem!

It should work. Fody is compatible with .NET Standard.

  • Create a new WPF app using the WPF App (.NET Core) template in Visual Studio 2019 or using the dotnet new wpf command
  • Install the Fody and PropertyChanged.Fody NuGet packages
  • Add a file named "FodyWeavers.xml" with the following contents to the project:

     <Weavers> <PropertyChanged /> </Weavers>
  • Build

If you then decompile the assembly using a decompiler such as for example dotPeek , you should see the injected code as expected, eg:

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);
    }
}

Costura didnt work in wpf with .net core 3.1 for me either. In .net core 3.1 you can use this instead:

  • Build -> publish -> create profile -> Edit "Configuration"
  • Target Runtime = win-x64 (or what ever target system you want, but NOT "portable")
  • expand "File Publish Options"
  • check: Produce single file
  • save

When you now choose build -> publish -> publish button it will create the single file.

It seems to be that they stopped the costura project because of the "Single-file executables" feature of .net core. Though this feature is still behind costura because you have to set a target runtime.

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

In dotnet core 3 there are two new features

Single-file executables Assembly linking

With these features included in the dotnet tool set, the value proposition of Costura is greatly diminished. With that in mind I think long term Costura should cease to be used as people transition over.

Please comment with any input.

Plan:

 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

update for .NET 5:
for .NET 5 and the current visual studio version 16.10.2 the wizard changed. I could not get this to work with the wizard anymore though i checked the options for single file etc.. But using the console worked: tools -> command line -> developer command prompt -> enter this:

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

.NET 5 not compiling to single file executables

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