Skip to content

Commit

Permalink
add dotnet build support
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 8, 2018
1 parent b639908 commit 5e48155
Show file tree
Hide file tree
Showing 32 changed files with 244 additions and 416 deletions.
4 changes: 0 additions & 4 deletions AssemblyToProcess/AssemblyInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion AssemblyToProcess/ClassWithObsoleteOnGetSet.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public class ClassWithObsoleteOnGetSet
{
public string PropertyToMark { [ObsoleteEx]get; [ObsoleteEx]set; }
public string PropertyToMark { [ObsoleteEx] get; [ObsoleteEx] set; }
}
24 changes: 20 additions & 4 deletions AssemblyToProcess/InterfaceToMark.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
using System;

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public interface InterfaceToMark
{
[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
string PropertyToMark { get; set; }

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
void MethodToMark();

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
event EventHandler EventToMark;
}
6 changes: 5 additions & 1 deletion AssemblyToProcess/Sample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Before
{
[ObsoleteEx(Message = "Custom message.", ReplacementTypeOrMember = "NewClass", TreatAsErrorFromVersion = "2.0", RemoveInVersion = "3.0")]
[ObsoleteEx(
Message = "Custom message.",
ReplacementTypeOrMember = "NewClass",
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "3.0")]
public class ClassToMark
{
}
Expand Down
30 changes: 25 additions & 5 deletions AssemblyToProcess/StructToMark.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
using System;
#pragma warning disable 67

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public struct StructToMark
{
[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public string PropertyToMark { get; set; }

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public string FieldToMark;

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public void MethodToMark() { }

[ObsoleteEx(TreatAsErrorFromVersion = "2.0", RemoveInVersion = "4.0", Message = "Custom message.", ReplacementTypeOrMember = "NewThing")]
[ObsoleteEx(
TreatAsErrorFromVersion = "2.0",
RemoveInVersion = "4.0",
Message = "Custom message.",
ReplacementTypeOrMember = "NewThing")]
public event EventHandler EventToMark;
}
4 changes: 0 additions & 4 deletions CommonAssemblyInfo.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Project>
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageVersion>4.3.5</PackageVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>
7 changes: 2 additions & 5 deletions Obsolete.Fody/AttributeFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@ void InnerProcess(IMemberDefinition memberDefinition)
LogError(error);
}
}
else
else if (memberDefinition is PropertyDefinition propertyDefinition)
{
if (memberDefinition is PropertyDefinition propertyDefinition)
{
throwsNotImplemented = ThrowsNotImplemented(propertyDefinition);
}
throwsNotImplemented = ThrowsNotImplemented(propertyDefinition);
}

customAttributes.Remove(obsoleteExAttribute);
Expand Down
3 changes: 1 addition & 2 deletions Obsolete.Fody/BrowsableAttributeAdder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public void AddEditorBrowsableAttribute(Collection<CustomAttribute> customAttrib
{
return;
}
var customAttribute = new CustomAttribute(EditorBrowsableConstructor);
customAttribute.ConstructorArguments.Add(new CustomAttributeArgument(EditorBrowsableStateType, AdvancedStateConstant));
var customAttribute = new CustomAttribute(EditorBrowsableConstructor); var customAttributeArgument = new CustomAttributeArgument(EditorBrowsableStateType, AdvancedStateConstant); customAttribute.ConstructorArguments.Add(customAttributeArgument);
customAttributes.Add(customAttribute);
}
}
Expand Down
15 changes: 3 additions & 12 deletions Obsolete.Fody/EditorBrowsableAttributeFinder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;

Expand All @@ -8,23 +7,15 @@ public partial class ModuleWeaver
public TypeDefinition EditorBrowsableStateType;
public int AdvancedStateConstant;

void FindEditorBrowsableTypes(List<TypeDefinition> typeDefinitions)
void FindEditorBrowsableTypes()
{
if (!HideObsoleteMembers)
{
return;
}
var attributeType = typeDefinitions.FirstOrDefault(x => x.Name == "EditorBrowsableAttribute");
if (attributeType == null)
{
throw new WeavingException("Could not find EditorBrowsableAttribute");
}
var attributeType = FindType("System.ComponentModel.EditorBrowsableAttribute");
EditorBrowsableConstructor = ModuleDefinition.ImportReference(attributeType.Methods.First(IsDesiredConstructor));
EditorBrowsableStateType = typeDefinitions.FirstOrDefault(x => x.Name == "EditorBrowsableState");
if (EditorBrowsableStateType == null)
{
throw new WeavingException("Could not find EditorBrowsableAttribute");
}
EditorBrowsableStateType = FindType("System.ComponentModel.EditorBrowsableState");
var fieldDefinition = EditorBrowsableStateType.Fields.First(x => x.Name == "Advanced");
AdvancedStateConstant = (int) fieldDefinition.Constant;
}
Expand Down
64 changes: 12 additions & 52 deletions Obsolete.Fody/ModuleWeaver.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Mono.Cecil;
using System.Collections.Generic;
using Fody;

public partial class ModuleWeaver
public partial class ModuleWeaver:BaseModuleWeaver
{
public SemanticVersion assemblyVersion;
public Action<string> LogInfo { get; set; }
public Action<string> LogWarning { get; set; }
public Action<string> LogError { get; set; }
public ModuleDefinition ModuleDefinition { get; set; }
public IAssemblyResolver AssemblyResolver { get; set; }
public XElement Config { get; set; }

public ModuleWeaver()
{
LogInfo = s => { };
LogWarning = s => { };
LogError = s => { };
}

public void Execute()
public override void Execute()
{
ReadConfig();
var systemTypes = FindSystemTypes();
FindEditorBrowsableTypes(systemTypes);
FindObsoleteType(systemTypes);
FindEditorBrowsableTypes();
FindObsoleteType();

var version = ModuleDefinition.Assembly.Name.Version;
assemblyVersion = new SemanticVersion
Expand All @@ -37,38 +20,15 @@ public void Execute()
};

ProcessAssembly();

CleanReferences();
}

public List<TypeDefinition> FindSystemTypes()
public override IEnumerable<string> GetAssembliesForScanning()
{
var types = new List<TypeDefinition>();

AddAssemblyIfExists("mscorlib", types);
AddAssemblyIfExists("System", types);
AddAssemblyIfExists("System.Runtime", types);
AddAssemblyIfExists("netstandard", types);

return types;
yield return "mscorlib";
yield return "System";
yield return "System.Runtime";
yield return "netstandard";
}

void AddAssemblyIfExists(string name, List<TypeDefinition> types)
{
try
{
var msCoreLibDefinition = AssemblyResolver.Resolve(new AssemblyNameReference(name, null));

if (msCoreLibDefinition != null)
{
var module = msCoreLibDefinition.MainModule;
types.AddRange(module.Types);
types.AddRange(module.ExportedTypes.Select(x => x.Resolve()).Where(x => x != null));
}
}
catch (AssemblyResolutionException)
{
LogInfo($"Failed to resolve '{name}'. So skipping its types.");
}
}
public override bool ShouldCleanReference => true;
}
20 changes: 3 additions & 17 deletions Obsolete.Fody/Obsolete.Fody.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452;netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>net46;netstandard2.0</TargetFrameworks>
<DebugType>portable</DebugType>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<PackageReference Include="FodyCecil" Version="2.*" />
<PackageReference Include="PepitaPackage" Version="*" />
<PackageReference Include="FodyHelpers" Version="2.*" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Compile Include="..\CommonAssemblyInfo.cs" />
</ItemGroup>
<Target Name="BuildNugets" AfterTargets="CopyFilesToOutputDirectory">
<ItemGroup>
<FilesToDelete Include="$(SolutionDir)nugets\**\*.*" />
</ItemGroup>
<Delete Files="@(FilesToDelete)" />
<MakeDir Directories="$(SolutionDir)nugets" />
<Copy SourceFiles="$(SolutionDir)Obsolete\bin\$(ConfigurationName)\net452\Obsolete.dll" DestinationFolder="$(SolutionDir)nugets\lib\net452" />
<Copy SourceFiles="$(SolutionDir)Obsolete\bin\$(ConfigurationName)\netstandard1.4\Obsolete.dll" DestinationFolder="$(SolutionDir)nugets\lib\netstandard1.4" />
<Copy SourceFiles="$(ProjectDir)Obsolete.Fody.nuspec" DestinationFolder="$(SolutionDir)nugets" />
<Copy SourceFiles="$(ProjectDir)bin\$(ConfigurationName)\net452\Obsolete.Fody.dll" DestinationFolder="$(SolutionDir)nugets" />
<Copy SourceFiles="$(ProjectDir)bin\$(ConfigurationName)\net452\Obsolete.Fody.pdb" DestinationFolder="$(SolutionDir)nugets" />
<PepitaPackage.CreatePackageTask NuGetBuildDirectory="$(SolutionDir)nugets" MetadataAssembly="$(ProjectDir)bin\$(ConfigurationName)\net452\Obsolete.Fody.dll" />
</Target>
</Project>
21 changes: 0 additions & 21 deletions Obsolete.Fody/Obsolete.Fody.nuspec

This file was deleted.

10 changes: 2 additions & 8 deletions Obsolete.Fody/ObsoleteTypeFinder.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;

public partial class ModuleWeaver
{
public MethodReference ObsoleteConstructorReference;

public void FindObsoleteType(List<TypeDefinition> systemTypes)
public void FindObsoleteType()
{
var obsoleteDefinition = systemTypes
.FirstOrDefault(x => x.Name == "ObsoleteAttribute");
if (obsoleteDefinition == null)
{
throw new WeavingException("Could not find ObsoleteAttribute");
}
var obsoleteDefinition = FindType("System.ObsoleteAttribute");
var constructor = obsoleteDefinition.Methods.First(x =>
x.Parameters.Count == 2
&& x.Parameters[0].ParameterType.Name == "String"
Expand Down
17 changes: 0 additions & 17 deletions Obsolete.Fody/ReferenceCleaner.cs

This file was deleted.

1 change: 0 additions & 1 deletion Obsolete.Fody/WeavingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ public class WeavingException : Exception
public WeavingException(string message)
: base(message)
{

}
}
4 changes: 0 additions & 4 deletions Obsolete.Fody/packages.config

This file was deleted.

Loading

0 comments on commit 5e48155

Please sign in to comment.