Obfuscar SkipType 配置元素不适用于枚举

Obfuscar SkipType configuration element is not working for enums

Obfuscar SkipType 配置元素似乎不适用于枚举。这是我的最小配置文件。

<?xml version="1.0"?>
<configuration>

  <startup><supportedRuntime version="v4.0" 
     sku=".NETFramework,Version=v4.0,Profile=Client"/>
  </startup>

  <Obfuscator>

    <Var name="InPath"  
value="\users\user\docs\vs2013\projects\wpfapp\wpfapp\bin\debug" />
    <Var name="OutPath" 
value="\users\user\docs\vs2013\projects\wpfapp\wpfapp\bin\debug" />

    <Module file="$(InPath)\wpfapp.exe" />

    <Var name="KeepPublicApi" value="true" />
    <Var name="HidePrivateApi" value="true" />

    <SkipType name="WpfApp.Category" skipFields="true" skipProperties="true" />

  </Obfuscator>

</configuration>

映射输出文件显示跳过无效,枚举类型 Category 已重命名。

Renamed Types:

[WpfApp]WpfApp.Category -> [WpfApp]A.a
{
    WpfApp.Category [WpfApp]WpfApp.Category WpfApp.Category::Low -> A
    WpfApp.Category [WpfApp]WpfApp.Category WpfApp.Category::High -> a

    System.Int32 [WpfApp]System.Int32 WpfApp.Category::value__ skipped:  special name
}

编辑: 元素 <SkipType name="WpfApp.Category" /> 导致同样的问题。

编辑: 元素 <SkipType name="WpfApp.Category" skipFields="true" /> 导致同样的问题。

编辑: 元素 <SkipField type="WpfApp.Category" name="*" /> 导致同样的问题。

编辑:这对

<SkipField type="WpfApp.Category" name="Low" />

<SkipField type="WpfApp.Category" name="High" /> 导致同样的问题。

来源:

namespace WpfApp
{
    public enum Category { Low, High }

    //[System.Reflection.Obfuscation]
    public partial class MainWindow : Window
    {
        private ViewModel ViewModel;

        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this.ViewModel = new ViewModel();
        }

        private void MyButtonClick(object sender, RoutedEventArgs e)
        {
            this.ViewModel.Process(MyTextBox.Text);
        }
    }

    internal class ViewModel : WpfNotifier
    {
        private const float DefaultKilograms = 80.0f;

        private string _kilograms;
        public string Kilograms // WPF binds here
        {
            get { return this._kilograms; }
            set { this._kilograms = value; NotifyPropertyChanged(); }
        }
        private string _resultText;
        public string ResultText // WPF binds here
        {
            get { return this._resultText; }
            set { this._resultText = value; NotifyPropertyChanged(); }
        }

        internal void Process(string input)
        {
            float kilograms;
            if (Single.TryParse(input, out kilograms))
            {
                Category c = (kilograms > 100.0f) ? Category.High : Category.Low;
                this.ResultText = c.ToString();
            }
            else
            {
                this.Kilograms = ViewModel.DefaultKilograms.ToString();
            }
        }
    }

    public class WpfNotifier : INotifyPropertyChanged
    {
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged; // public for interface

        internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            else
                ; // it is harmless to fail to notify before the window has been loaded and rendered
        }
    }
}

这是一个错误还是我的用法有误?

你的用法是错误的。如果您检查 the documentation,您会看到 <SkipType> 标签必须放入 <Module> 标签中。否则,Obfuscar 不知道 module/assembly 这个跳过规则在哪里生效。所以你应该试试

<Module file="$(InPath)\wpfapp.exe">
    <SkipType name="WpfApp.Category" skipFields="true" skipProperties="true" />
</Module>