Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions AssemblyPublicizer/AsmModuleExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ namespace AssemblyPublicizer
{
public static class AsmModuleExtension
{
public static void Publicize(this ModuleDefinition moduleDefinition, bool publicizeExplicitImpls = false)
public static void Publicize(this ModuleDefinition moduleDefinition, bool publicizeExplicitImpls = false, bool publicizeCompilerGeneratedFields = false)
{
foreach (var type in moduleDefinition.GetAllTypes())
{
type.IsSealed = false;
if (type.IsNested)
type.IsNestedPublic = true;
else
Expand All @@ -27,7 +28,10 @@ public static void Publicize(this ModuleDefinition moduleDefinition, bool public

foreach (var field in type.Fields)
{
field.IsPublic = true;
if (publicizeCompilerGeneratedFields || !field.HasCustomAttribute("System.Runtime.CompilerServices", "CompilerGeneratedAttribute"))
{
field.IsPublic = true;
}
}
}
}
Expand Down
64 changes: 35 additions & 29 deletions AssemblyPublicizer/AssemblyPublicizer.csproj
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>9</LangVersion>
<Nullable>enable</Nullable>
<DevelopmentDependency>true</DevelopmentDependency>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<IncludeBuildOutput>true</IncludeBuildOutput>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ContentTargetFolders>build</ContentTargetFolders>
<Title>Assembly Publicizer</Title>
<Description>MSBuild Task to publicize assemblies</Description>
<Authors>vikigenius</Authors>
<RepositoryUrl>https://github.com/vikigenius/AssemblyPublicizer</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>2021 Vikash Balasubramanian</Copyright>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<Version>1.0.2</Version>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<DevelopmentDependency>true</DevelopmentDependency>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<IncludeBuildOutput>true</IncludeBuildOutput>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ContentTargetFolders>build</ContentTargetFolders>
<Title>Assembly Publicizer</Title>
<Description>MSBuild Task to publicize assemblies</Description>
<Authors>vikigenius</Authors>
<RepositoryUrl>https://github.com/vikigenius/AssemblyPublicizer</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>2021 Vikash Balasubramanian</Copyright>
<RepositoryType>git</RepositoryType>
<AssemblyVersion>1.0.4</AssemblyVersion>
<FileVersion>1.0.4</FileVersion>
<Version>1.0.4</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<NoPackageAnalysis>true</NoPackageAnalysis>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
<DebugType>none</DebugType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AsmResolver.DotNet" Version="4.7.1" PrivateAssets="All" />
<PackageReference Include="ILRepack.Lib.MSBuild" Version="2.1.17.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" Version="16.11.0" PrivateAssets="All" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.11.0" PrivateAssets="All" ExcludeAssets="runtime" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AsmResolver.DotNet" Version="5.5.0" PrivateAssets="All" />
<PackageReference Include="ILRepack.Lib.MSBuild" Version="2.1.18" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" Version="17.8.3" PrivateAssets="All" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.8.3" PrivateAssets="All" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
<Content Include="AssemblyPublicizer.props" />
</ItemGroup>
<ItemGroup>
<Content Include="AssemblyPublicizer.props" Pack="true" PackagePath="build\" />
<Content Include="AssemblyPublicizer.props" Pack="true" PackagePath="buildMultiTargeting\" />
<None Include="..\README.md" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions AssemblyPublicizer/AssemblyPublicizer.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project TreatAsLocalProperty="PublicizeTaskAssembly">
<PropertyGroup>
<PublicizeTaskAssembly>$(MSBuildThisFileDirectory)..\lib\net472\$(MSBuildThisFileName).dll</PublicizeTaskAssembly>
</PropertyGroup>
<UsingTask TaskName="AssemblyPublicizer.PublicizeTask" AssemblyFile="$(PublicizeTaskAssembly)" />
</Project>
<PropertyGroup>
<PublicizeTaskAssembly>$(MSBuildThisFileDirectory)..\tasks\net472\$(MSBuildThisFileName).dll</PublicizeTaskAssembly>
</PropertyGroup>
<UsingTask TaskName="AssemblyPublicizer.PublicizeTask" AssemblyFile="$(PublicizeTaskAssembly)" />
</Project>
6 changes: 4 additions & 2 deletions AssemblyPublicizer/PublicizeTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class PublicizeTask : Microsoft.Build.Utilities.Task

public virtual bool PublicizeExplicitImpls { get; set; } = false;

public virtual bool PublicizeCompilerGeneratedFields { get; set; } = false;

public override bool Execute()
{
Log.LogMessage($"Publicizing {InputAssemblies.Length} input assemblies provided");
Expand Down Expand Up @@ -46,7 +48,7 @@ private bool PublicizeItem(string assemblyPath)
Log.LogMessage(MessageImportance.High, $"Generating publicized assembly from {assemblyPath}");

var moduleDefinition = ModuleDefinition.FromFile(assemblyPath);
moduleDefinition.Publicize(PublicizeExplicitImpls);
moduleDefinition.Publicize(PublicizeExplicitImpls, PublicizeCompilerGeneratedFields);

if (!Directory.Exists(OutputDir))
{
Expand All @@ -72,7 +74,7 @@ private string ComputeHash(string filePath)
file.Close();
}

foreach (byte b in hash.Hash)
foreach (byte b in hash.Hash!)
res.Append(b.ToString("X2"));
}

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ It addresses one key issue with other publicizers in that, it avoids publicizing
2. Create the MSBuild Target. Properties are:
`InputAssemblies`: Assemblies to be publicized.
`OutputDir`: Output directory to store the publicized assemblies.
`PublicizeExplicitImpls`: Whether or not to publicize explicit implementation. (False by default).
`PublicizeExplicitImpls`: Whether or not to publicize explicit implementation. (False by default).
`PublicizeCompilerGeneratedFields`: Whether or not to publicize fields generated by the compiler. (False by default).