MSBuild: Fixed handling of satellite assemblies
This commit is contained in:
Родитель
90937e3a4b
Коммит
62bdb3ddae
|
@ -20,13 +20,14 @@ namespace Confuser.MSBuild.Tasks {
|
|||
project.Load(xmlDoc);
|
||||
project.OutputDirectory = Path.GetDirectoryName(OutputAssembly.ItemSpec);
|
||||
|
||||
var logger = new MSBuildLogger(Log);
|
||||
var parameters = new ConfuserParameters {
|
||||
Project = project,
|
||||
Logger = new MSBuildLogger(Log)
|
||||
Logger = logger
|
||||
};
|
||||
|
||||
ConfuserEngine.Run(parameters).Wait();
|
||||
return true;
|
||||
return !logger.HasError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Confuser.Core.Project;
|
||||
|
@ -15,6 +16,8 @@ namespace Confuser.MSBuild.Tasks {
|
|||
[Required]
|
||||
public ITaskItem AssemblyPath { get; set; }
|
||||
|
||||
public ITaskItem[] SatelliteAssemblyPaths { get; set; }
|
||||
|
||||
public ITaskItem KeyFilePath { get; set; }
|
||||
|
||||
[Required, Output]
|
||||
|
@ -37,6 +40,17 @@ namespace Confuser.MSBuild.Tasks {
|
|||
mainModule.SNKeyPath = KeyFilePath.ItemSpec;
|
||||
}
|
||||
|
||||
if (SatelliteAssemblyPaths != null) {
|
||||
foreach (var satelliteAssembly in SatelliteAssemblyPaths) {
|
||||
if (!string.IsNullOrWhiteSpace(satelliteAssembly?.ItemSpec)) {
|
||||
var satelliteModule = GetOrCreateProjectModule(project, satelliteAssembly.ItemSpec);
|
||||
if (!string.IsNullOrWhiteSpace(KeyFilePath?.ItemSpec)) {
|
||||
satelliteModule.SNKeyPath = KeyFilePath.ItemSpec;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var probePath in References.Select(r => Path.GetDirectoryName(r.ItemSpec)).Distinct()) {
|
||||
project.ProbePaths.Add(probePath);
|
||||
}
|
||||
|
@ -54,6 +68,11 @@ namespace Confuser.MSBuild.Tasks {
|
|||
return module;
|
||||
}
|
||||
}
|
||||
|
||||
if (assemblyPath.StartsWith(project.BaseDirectory)) {
|
||||
assemblyPath = assemblyPath.Substring(project.BaseDirectory.Length).TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
||||
}
|
||||
|
||||
var result = new ProjectModule {
|
||||
Path = assemblyPath,
|
||||
IsExternal = isExternal
|
||||
|
|
|
@ -6,6 +6,8 @@ using ILogger = Confuser.Core.ILogger;
|
|||
namespace Confuser.MSBuild.Tasks {
|
||||
internal sealed class MSBuildLogger : ILogger {
|
||||
private readonly TaskLoggingHelper loggingHelper;
|
||||
|
||||
internal bool HasError { get; private set; }
|
||||
|
||||
internal MSBuildLogger(TaskLoggingHelper loggingHelper) =>
|
||||
this.loggingHelper = loggingHelper ?? throw new ArgumentNullException(nameof(loggingHelper));
|
||||
|
@ -18,17 +20,27 @@ namespace Confuser.MSBuild.Tasks {
|
|||
|
||||
void ILogger.EndProgress() {}
|
||||
|
||||
void ILogger.Error(string msg) =>
|
||||
void ILogger.Error(string msg) {
|
||||
loggingHelper.LogError(msg);
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
void ILogger.ErrorException(string msg, Exception ex) {
|
||||
loggingHelper.LogError(msg);
|
||||
loggingHelper.LogErrorFromException(ex);
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
void ILogger.ErrorFormat(string format, params object[] args) => loggingHelper.LogError(format, args);
|
||||
void ILogger.ErrorFormat(string format, params object[] args) {
|
||||
loggingHelper.LogError(format, args);
|
||||
HasError = true;
|
||||
}
|
||||
|
||||
void ILogger.Finish(bool successful) {}
|
||||
void ILogger.Finish(bool successful) {
|
||||
if (!successful) {
|
||||
HasError = false;
|
||||
}
|
||||
}
|
||||
|
||||
void ILogger.Info(string msg) => loggingHelper.LogMessage(MessageImportance.Normal, msg);
|
||||
|
||||
|
|
|
@ -11,40 +11,59 @@
|
|||
<ConfuserProject Condition="Exists('$(MSBuildProjectDirectory)\$(MSBuildProjectName).crproj')">$(MSBuildProjectDirectory)\$(MSBuildProjectName).crproj</ConfuserProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target AfterTargets="ResolveReferences"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true"
|
||||
Name="CreateConfuserProject"
|
||||
DependsOnTargets="$(CreateConfuserProjectDependsOnTargets)"
|
||||
Inputs="@(IntermediateAssembly->'%(FullPath)');$(ConfuserProject)"
|
||||
<PropertyGroup>
|
||||
<ConfuserExDependsOn>
|
||||
CreateConfuserProject;
|
||||
ConfuseAssembly;
|
||||
_ReplaceOutputWithConfusedAssemblies;
|
||||
_ReplaceDebugOutputWithConfusedAssemblies;
|
||||
CopyConfusedFilesToOutputDirectory;
|
||||
</ConfuserExDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<Target Name="ConfuserEx"
|
||||
DependsOnTargets="$(ConfuserExDependsOn)"
|
||||
BeforeTargets="PrepareForRun" />
|
||||
|
||||
<PropertyGroup>
|
||||
<CreateConfuserProjectDependsOn>
|
||||
ResolveReferences;
|
||||
ComputeIntermediateSatelliteAssemblies
|
||||
</CreateConfuserProjectDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="CreateConfuserProject"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true"
|
||||
DependsOnTargets="$(CreateConfuserProjectDependsOn)"
|
||||
Inputs="@(IntermediateAssembly->'%(FullPath)');$(ConfuserProject);@(IntermediateSatelliteAssembliesWithTargetPath)"
|
||||
Outputs="@(IntermediateAssembly->'$(IntermediateOutputPath)%(Filename).crproj')">
|
||||
<Confuser.MSBuild.Tasks.CreateProjectTask
|
||||
SourceProject="$(ConfuserProject)"
|
||||
References="@(ReferencePath)"
|
||||
AssemblyPath="@(IntermediateAssembly)"
|
||||
SatelliteAssemblyPaths="@(IntermediateSatelliteAssembliesWithTargetPath)"
|
||||
KeyFilePath="$(ConfuserKeyFile)"
|
||||
ResultProject="@(IntermediateAssembly->'$(IntermediateOutputPath)%(Filename).crproj')"/>
|
||||
</Target>
|
||||
|
||||
<PropertyGroup>
|
||||
<ConfuseAssemblyDependsOn>
|
||||
$(ConfuseAssemblyDependsOn);
|
||||
CreateConfuserProject
|
||||
</ConfuseAssemblyDependsOn>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target AfterTargets="Compile"
|
||||
<Target Name="ConfuseAssembly"
|
||||
Condition="Exists('@(IntermediateAssembly)') And $(DesignTimeBuild) != true And $(Obfuscate) == true"
|
||||
Name="ConfuseAssembly"
|
||||
DependsOnTargets="$(ConfuseAssemblyDependsOn)"
|
||||
Inputs="@(IntermediateAssembly->'%(FullPath)');@(IntermediateAssembly->'$(IntermediateOutputPath)%(Filename).crproj')"
|
||||
Outputs="@(IntermediateAssembly->'$(ConfuserIntermediateOutputPath)%(Filename)%(Extension)')">
|
||||
Outputs="@(IntermediateAssembly->'$(ConfuserIntermediateOutputPath)%(Filename)%(Extension)');@(IntermediateSatelliteAssembliesWithTargetPath->'$(ConfuserIntermediateOutputPath)%(TargetPath)')">
|
||||
<Confuser.MSBuild.Tasks.ConfuseTask
|
||||
Project="@(IntermediateAssembly->'$(IntermediateOutputPath)%(Filename).crproj')"
|
||||
OutputAssembly="@(IntermediateAssembly->'$(ConfuserIntermediateOutputPath)%(Filename)%(Extension)')" />
|
||||
</Target>
|
||||
|
||||
<Target Name="_ReplaceOutputWithConfusedAssemblies"
|
||||
AfterTargets="ConfuseAssembly"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true and '$(ConfuserReplaceOutput)' == 'true'"
|
||||
DependsOnTargets="ConfuseAssembly">
|
||||
<CreateItem Include="@(IntermediateAssembly->'$(ConfuserIntermediateOutputPath)%(Filename)%(Extension)')">
|
||||
|
@ -59,8 +78,7 @@
|
|||
</Target>
|
||||
|
||||
<Target Name="_ReplaceDebugOutputWithConfusedAssemblies"
|
||||
AfterTargets="ConfuseAssembly"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true and '$(ConfuserReplaceOutput)' == 'true' and '@(_DebugSymbolsIntermediatePath') != ''"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true and '$(ConfuserReplaceOutput)' == 'true' and '@(_DebugSymbolsIntermediatePath)' != ''"
|
||||
DependsOnTargets="ConfuseAssembly">
|
||||
<CreateItem Include="@(IntermediateAssembly->'$(ConfuserIntermediateOutputPath)%(Filename).pdb')">
|
||||
<Output TaskParameter="Include" ItemName="_ConfusedDebugSymbolsIntermediatePath" />
|
||||
|
@ -74,8 +92,7 @@
|
|||
</Target>
|
||||
|
||||
<Target Name="CopyConfusedFilesToOutputDirectory"
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true and '$(ConfuserReplaceOutput)' != 'true'"
|
||||
AfterTargets="CopyFilesToOutputDirectory">
|
||||
Condition="$(DesignTimeBuild) != true And $(Obfuscate) == true and '$(ConfuserReplaceOutput)' != 'true'">
|
||||
<PropertyGroup>
|
||||
<!-- By default we're not using Hard Links to copy to the output directory, and never when building in VS -->
|
||||
<CreateHardLinksForCopyFilesToOutputDirectoryIfPossible Condition="'$(BuildingInsideVisualStudio)' == 'true' or '$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)' == ''">false</CreateHardLinksForCopyFilesToOutputDirectoryIfPossible>
|
||||
|
@ -99,7 +116,7 @@
|
|||
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
Condition="'$(CopyBuildOutputToOutputDirectory)' == 'true' and '$(SkipCopyBuildProduct)' != 'true'">
|
||||
|
||||
<Output TaskParameter="DestinationFiles" ItemName="MainAssembly"/>
|
||||
<Output TaskParameter="DestinationFiles" ItemName="ConfusedMainAssembly"/>
|
||||
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
|
||||
|
||||
</Copy>
|
||||
|
@ -119,5 +136,21 @@
|
|||
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
|
||||
|
||||
</Copy>
|
||||
|
||||
<!-- Copy the satellite assemblies (.resources.dll), if any -->
|
||||
<Copy
|
||||
SourceFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(ConfuserIntermediateOutputPath)%(TargetPath)')"
|
||||
DestinationFiles="@(IntermediateSatelliteAssembliesWithTargetPath->'$(ConfuserOutDir)%(TargetPath)')"
|
||||
SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
|
||||
OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
|
||||
Retries="$(CopyRetryCount)"
|
||||
RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
|
||||
UseHardlinksIfPossible="$(CreateHardLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyFilesToOutputDirectoryIfPossible)"
|
||||
Condition="'$(_DebugSymbolsProduced)'=='true' and '$(SkipCopyingSymbolsToOutputDirectory)' != 'true' and '$(CopyOutputSymbolsToOutputDirectory)'=='true'">
|
||||
|
||||
<Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>
|
||||
|
||||
</Copy>
|
||||
</Target>
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче