Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Project>
- <PropertyGroup>
- <!-- Suppress nuget warnings -->
- <NoWarn>$(NoWarn);NU5128;NU5125</NoWarn>
- </PropertyGroup>
- <Target Name="AfterInitialization" AfterTargets="Initialization" Condition="'$(Configuration)' == 'Release'">
- <PropertyGroup>
- <ObfuscateTest>false</ObfuscateTest>
- <GenerateNugetTest>false</GenerateNugetTest>
- <ProjectParentDirectory>$([System.IO.Directory]::GetParent($(MSBuildProjectDirectory)))</ProjectParentDirectory>
- <WebApplicationGuid>{349C5851-65DF-11DA-9384-00065B846F21}</WebApplicationGuid>
- <GenerateNuget Condition="$(GenerateNuget) AND $(GenerateNugetTest)">false</GenerateNuget>
- <GenerateNuget Condition="$(GenerateNuget) AND $(ProjectTypeGuids.Split(';')[0]) == $(WebApplicationGuid)">false</GenerateNuget>
- <GenerateNuget Condition="$(GenerateNuget) AND $(OutputType) == 'WinExe'">false</GenerateNuget>
- <GenerateNuget Condition="$(GenerateNuget) AND Exists('$(MSBuildProjectDirectory)\.nugetignore')">false</GenerateNuget>
- <Obfuscate Condition="$(Obfuscate) AND $(ObfuscateTest)">false</Obfuscate>
- <Obfuscate Condition="$(Obfuscate) AND Exists('$(MSBuildProjectDirectory)\.obfuscateignore')">false</Obfuscate>
- <ObfuscatedFolder>$(MSBuildThisFileDirectory)\Anti Debug</ObfuscatedFolder>
- <ObfuscatedFolder Condition="!$(GenerateNuget)">$(TargetDir)</ObfuscatedFolder>
- <ObfuscatorPath>C:\Program Files (x86)\Eziriz\.NET Reactor\dotNET_Reactor.Console.exe</ObfuscatorPath>
- <TimestampServer>http://timestamp.digicert.com</TimestampServer>
- <NugetPath>$(MSBuildThisFileDirectory)nuget.exe</NugetPath>
- <NugetOutputFolder>C:\LocalNuget</NugetOutputFolder>
- <!-- Signing section are turned off now during a very slow with self-certificate certficiates. Enable it later when purchase code signing-->
- <!-- -spcfile "$(MSBuildThisFileDirectory)\Certificate.pfx" -pvkpassword "encrypted:OKeTYmOwxNYEsc5YhYllfg==" -sha1_timestamp_server "" -sha256_timestamp_server "$(TimestampServer)" -->
- <ObfuscatorParameters>-antitamp 1 -anti_debug 1 -hide_calls 1 -hide_calls_internals 1 -control_flow_obfuscation 1 -flow_level 9 -resourceencryption 1 -antistrong 1 -virtualization 1 -necrobit 1 -mapping_file 1 -mapping_file_overwrite 1 -mapping_filename "<ProtectedAssemblyLocation>\<AssemblyName>.nrmap" </ObfuscatorParameters>
- <ObfuscatorParameters Condition="!$(GenerateNuget)">$(ObfuscatorParameters.Replace('-mapping_file 1', ''))</ObfuscatorParameters>
- </PropertyGroup>
- </Target>
- <!-- Create Nuspec File -->
- <Target Name="GenerateNuspecFile" BeforeTargets="ResolveAssemblyReferences"
- Condition="'$(Configuration)' == 'Release' AND $(GenerateNuget)">
- <PropertyGroup>
- <DotIndex>$(AssemblyName.IndexOf('.'))</DotIndex>
- <OurAssembly>$(AssemblyName)</OurAssembly>
- <OurAssembly Condition ="$(DotIndex) != -1">$(AssemblyName.SubString(0, $(DotIndex)))</OurAssembly>
- </PropertyGroup>
- <ItemGroup>
- <!-- Get all references -->
- <MyReference Include="@(ReferenceCopyLocalPaths)" Condition="%(extension) == '.dll'">
- <ReferenceDLL>%(identity)</ReferenceDLL>
- <ReferenceName>%(filename)</ReferenceName>
- <ReferenceExtension>%(extension)</ReferenceExtension>
- <IsOurAssembly>$([System.String]::Copy('%(MyReference.ReferenceName)').StartsWith('$(OurAssembly)'))</IsOurAssembly>
- <FirstDir>$([System.IO.Directory]::GetParent(%(RelativeDir)))</FirstDir>
- <LibDir>$([System.IO.Path]::GetFileNameWithoutExtension(%(MyReference.FirstDir)))</LibDir>
- <SecondDir>$(FirstDir)</SecondDir>
- <SecondDir Condition="$(LibDir) != 'lib'">$([System.IO.Directory]::GetParent(%(MyReference.FirstDir)))</SecondDir>
- <VersionDir>$([System.IO.Directory]::GetParent(%(MyReference.SecondDir)))</VersionDir>
- <PackageDir>$([System.IO.Directory]::GetParent(%(MyReference.VersionDir)))</PackageDir>
- <PackageID>$([System.IO.Path]::GetFileName(%(MyReference.PackageDir)))</PackageID>
- <NuspecFile>%(MyReference.VersionDir)\%(MyReference.PackageID).nuspec</NuspecFile>
- </MyReference>
- <!-- Get Non nuget references -->
- <ExcludedReference Condition="@(MyReference) != ''" Include="@(MyReference -> '%(PackageID)')" Exclude="@(PackageReference -> '%(identity)')"/>
- <!-- Get nuget references after exclude non-nuget references -->
- <MyPackage Condition="@(MyReference) != ''" Include="@(MyReference -> '%(PackageID)')" Exclude="@(ExcludedReference -> '%(identity)')"/>
- <!-- Read Nuspec File -->
- <NuspecContent Condition="@(MyPackage) != ''" Include="%(MyPackage.NuspecFile)">
- <Content>$([System.IO.File]::ReadAllText(%(MyPackage.NuspecFile)))</Content>
- <PackageIDRegex><id>(.*?)</id></PackageIDRegex>
- <PackageID>$([System.Text.RegularExpressions.Regex]::Match('%(NuspecContent.Content)', '%(NuspecContent.PackageIDRegex)' ))</PackageID>
- <PackageID>$([System.String]::Copy('%(NuspecContent.PackageID)').Replace('<id>','').Replace('</id>', '').Trim())</PackageID>
- <VersionRegex><version>(.*?)</version></VersionRegex>
- <Version>$([System.Text.RegularExpressions.Regex]::Match('%(NuspecContent.Content)', '%(NuspecContent.VersionRegex)' ))</Version>
- <Version>$([System.String]::Copy('%(NuspecContent.Version)').Replace('<version>','').Replace('</version>', '').Trim())</Version>
- </NuspecContent>
- </ItemGroup>
- <!-- Generate Nuspec File with dependencies-->
- <PropertyGroup>
- <NewLine>%0d%0a</NewLine>
- <Space2>%20%20</Space2>
- <Space4>$(Space2)$(Space2)</Space4>
- <Space6>$(Space4)$(Space2)</Space6>
- <HasDependencies>false</HasDependencies>
- <HasDependencies Condition="@(MyPackage) != ''">true</HasDependencies>
- <Nuspec>$(Nuspec)<?xml version="1.0" encoding="utf-8"?>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)<package >$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space2)<metadata>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<id>$id$</id>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<version>$version$</version>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<title>$title$</title>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<authors>$author$</authors>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<owners>$author$</owners>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<requireLicenseAcceptance>false</requireLicenseAcceptance>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<licenseUrl>https://company.com</licenseUrl>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<icon>PackageIcon.png</icon>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<projectUrl>http://company.com</projectUrl>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<description>$description$</description>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<releaseNotes>$description$</releaseNotes>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<copyright>$copyright$</copyright>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<tags>$title$ company company.com</tags>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<dependencies>$(NewLine)</Nuspec>
- <Nuspec Condition="$(HasDependencies)">$(Nuspec)$(Space6)<group targetFramework=".NETFramework4.8">$(NewLine)</Nuspec>
- <Nuspec Condition="$(HasDependencies)">$(Nuspec)@(NuspecContent -> '$(Space6)<dependency id="%(PackageID)" version="%(Version)"/>', '$(NewLine)')$(NewLine)</Nuspec>
- <Nuspec Condition="$(HasDependencies)">$(Nuspec)$(Space6)</group>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)</dependencies>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space2)</metadata>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space2)<files>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space4)<file src="..\**\PackageIcon.png"/>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)$(Space2)</files>$(NewLine)</Nuspec>
- <Nuspec>$(Nuspec)</package>$(NewLine)</Nuspec>
- </PropertyGroup>
- <WriteLinesToFile Lines="$(Nuspec)" File="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuspec" Overwrite="true"/>
- </Target>
- <Target Name="ExcludeUnusedReferences" AfterTargets="ResolveAssemblyReferences" Condition="'$(Configuration)' == 'Release'">
- <ItemGroup>
- <!-- Exclude .xml, .pdb files -->
- <FilesToExclude Include="@(_ReferenceRelatedPaths)"/>
- <!-- Exclude satellites files -->
- <FilesToExclude Include="@(ReferenceSatellitePaths)"/>
- <ReferenceCopyLocalPaths Remove="@(FilesToExclude)"/>
- <!-- Exclude .dll nuget packages and take anti-debug obfuscated version -->
- <ReferenceCopyLocalPaths Remove="%(MyPackage.ReferenceDLL)" Condition="$(GenerateNuget) AND $(Obfuscate) AND @(MyPackage) != '' AND %(MyPackage.IsOurAssembly)"/>
- </ItemGroup>
- <Message Condition="@(FilesToExclude) != ''" Text="Excluded Files @(FilesToExclude -> '%(FileName)%(Extension)', ', ')"
- Importance="high"/>
- <Error Condition="$(GenerateNuget) AND $(Obfuscate) AND @(MyPackage) != '' AND %(MyPackage.IsOurAssembly) AND !Exists('$(ObfuscatedFolder)\%(MyPackage.ReferenceName)%(MyPackage.ReferenceExtension)')" Text="%(MyPackage.ReferenceName)%(MyPackage.ReferenceExtension) doesn't exists in $(ObfuscatedFolder) folder. Please rebuild references from their solutions."/>
- <Copy Condition="$(GenerateNuget) AND $(Obfuscate) AND @(MyPackage) != '' AND %(MyPackage.IsOurAssembly) AND Exists('$(ObfuscatedFolder)\%(MyPackage.ReferenceName)%(MyPackage.ReferenceExtension)')" SourceFiles="$(ObfuscatedFolder)\%(MyPackage.ReferenceName)%(MyPackage.ReferenceExtension)" DestinationFolder="$(TargetDir)"/>
- </Target>
- <Target Name="ExcludeUnusedCopiedfiles" AfterTargets="CopyFilesToOutputDirectory" Condition="'$(Configuration)' == 'Release'">
- <!-- Remove *.xml, *.pdb, other unused files that copied from packages-->
- <ItemGroup>
- <FileToExclude Include="@(_SourceItemsToCopyToOutputDirectory -> '$(TargetDir)\%(FileName)%(Extension)')" Condition="%(Extension) == '.pdb' OR %(Extension) == '.xml'"/>
- <_SourceItemsToCopyToOutputDirectory Remove="@(FileToExclude)"/>
- </ItemGroup>
- <Message Condition="@(FileToExclude) != ''" Text="Excluded Files @(FileToExclude -> '%(FullPath)', ', ')"
- Importance="high"/>
- </Target>
- <!-- Obfuscate Libraries and create Nuget package -->
- <Target Name="ObfuscateAndCreatePackage" Condition="'$(Configuration)' == 'Release' AND $(OutputType) == 'Library'"
- AfterTargets="AfterBuild" DependsOnTargets="AfterInitialization">
- <Error Condition="$(GenerateNuget) AND !Exists('$(NugetPath)')" Text="Nuget path not found $(NugetPath)"/>
- <Error Condition="Exists('$(ObfuscatorPath)') == false" Text="Obfuscator path not found $(ObfuscatorPath)"/>
- <!-- Obfuscate with anti-debug to Obfuscated folder or \Release path when GenerateNuget enabled -->
- <Exec Condition="$(Obfuscate)" Command=""$(ObfuscatorPath)" -file "$(TargetPath)" -targetfile "$(ObfuscatedFolder)\$(TargetFileName)" $(ObfuscatorParameters)"/>
- <!-- Obfuscate without anti-debug to /Release path for Nuget package for Developers -->
- <Exec Condition="$(Obfuscate) AND $(GenerateNuget)" Command=""$(ObfuscatorPath)" -file "$(TargetPath)" -targetfile "$(TargetPath)" $(ObfuscatorParameters.Replace('-anti_debug 1','').Replace('-mapping_file 1', ''))"/>
- <!-- Copy Package Icon to solution if not exists -->
- <Copy Condition="$(GenerateNuget) AND !Exists('$(ProjectParentDirectory)\PackageIcon.png')" SourceFiles="$(MSBuildThisFileDirectory)\PackageIcon.png;$(MSBuildThisFileDirectory)\PackageIcon.psd" DestinationFolder="$(ProjectParentDirectory)"/>
- <!-- Create Nuget package for developers without anti-debug -->
- <Exec Condition="$(GenerateNuget)" Command=""$(NugetPath)" pack "$(ProjectPath)" -Prop Configuration=Release -OutputDirectory "$(NugetOutputFolder)""/>
- <!-- Copy end-user anti-debug version from Obfuscated folder to /Release path -->
- <Copy Condition="$(Obfuscate) AND $(GenerateNuget)" SourceFiles="$(ObfuscatedFolder)\$(TargetFileName)" DestinationFolder="$(TargetDir)"/>
- <!-- Remove cached files -->
- <Delete Files="$(MSBuildProjectDirectory)\$(MSBuildProjectName).nuspec;$(TargetPath).hash"/>
- <OnError ExecuteTargets="ObfuscateAndCreatePackageError"/>
- </Target>
- <Target Name="ObfuscateAndCreatePackageError">
- <Delete Files="$(TargetPath)"/>
- <Message Text="(Error in ObfuscateAndCreatePackage Target). $(TargetPath) has been removed." Importance="high"/>
- </Target>
- </Project>
Advertisement
Add Comment
Please, Sign In to add comment