summaryrefslogtreecommitdiff
path: root/Tools/resources.targets
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/resources.targets')
-rwxr-xr-xTools/resources.targets168
1 files changed, 168 insertions, 0 deletions
diff --git a/Tools/resources.targets b/Tools/resources.targets
new file mode 100755
index 0000000000..910db3f79e
--- /dev/null
+++ b/Tools/resources.targets
@@ -0,0 +1,168 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <UsingTask TaskName="GenerateResourcesCode" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
+ <UsingTask TaskName="NormalizeAssemblyName" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll" />
+
+ <PropertyGroup>
+ <GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
+ <GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
+ </PropertyGroup>
+
+ <PropertyGroup>
+ <ResourcesSourceOutputDirectory Condition="'$(ResourcesSourceOutputDirectory)' == ''">$(MSBuildProjectDirectory)/Resources/</ResourcesSourceOutputDirectory>
+ <StringResourcesPath Condition="'$(StringResourcesPath)'=='' And Exists('$(ResourcesSourceOutputDirectory)Strings.resx')">$(ResourcesSourceOutputDirectory)Strings.resx</StringResourcesPath>
+ <ResourcesSourceFileExtension Condition="'$(MSBuildProjectExtension)' == '.csproj'">.cs</ResourcesSourceFileExtension>
+ <ResourcesSourceFileExtension Condition="'$(MSBuildProjectExtension)' == '.vbproj'">.vb</ResourcesSourceFileExtension>
+ <IntermediateResOutputFileFullPath>$(IntermediateOutputPath)SR$(ResourcesSourceFileExtension)</IntermediateResOutputFileFullPath>
+ <CommonSRSourceFile Condition="'$(CommonSRSourceFile)' == ''">$(CommonPath)/System/SR$(ResourcesSourceFileExtension)</CommonSRSourceFile>
+ <IntermediateCommonSRFileFullPath>$(IntermediateOutputPath)SR.common$(ResourcesSourceFileExtension)</IntermediateCommonSRFileFullPath>
+ <ShouldGenerateCommonSRFile Condition="'$(ShouldGenerateCommonSRFile)' == '' AND ('$(GenerateResourcesSRNamespace)' != '' OR '$(GenerateResourcesSRClassName)' != '')">true</ShouldGenerateCommonSRFile>
+ <DefineConstants Condition="'$(ConfigurationGroup)' == 'Debug'">$(DefineConstants);DEBUGRESOURCES</DefineConstants>
+ </PropertyGroup>
+
+ <PropertyGroup Condition="'$(BuildingUAPVertical)' == 'true'">
+ <CompileDependsOn>
+ CopyResxFilesToReswFiles;
+ $(CompileDependsOn);
+ </CompileDependsOn>
+ </PropertyGroup>
+
+ <Target Name="CalculateResourcesFileNames" Condition="'$(BuildingUAPVertical)' == 'true'">
+ <ItemGroup>
+ <_AllResxFiles Include="@(EmbeddedResource->'%(FullPath)')" Condition="'%(Extension)' == '.resx'">
+ <ReswName Condition="'%(EmbeddedResource.ReswName)' == ''">%(EmbeddedResource.ManifestResourceName)</ReswName>
+ </_AllResxFiles>
+ </ItemGroup>
+
+ <PropertyGroup>
+ <ProjectHasResources Condition="'@(_AllResxFiles)' != ''">true</ProjectHasResources>
+ <TestProjectNeedsModifiedPriFile Condition="'$(IsTestProject)' == 'true' AND '$(ProjectHasResources)' == 'true'">true</TestProjectNeedsModifiedPriFile>
+ <TestResourcesFolderPath Condition="'$(TestProjectNeedsModifiedPriFile)' == 'true'">$(RuntimePath)$(AssemblyName).Resw</TestResourcesFolderPath>
+ <_ResWDestinationPath Condition="'$(TestResourcesFolderPath)' != ''">$(TestResourcesFolderPath)</_ResWDestinationPath>
+ <_ResWDestinationPath Condition="'$(TestResourcesFolderPath)' == ''">$(ResourcesFolderPath)</_ResWDestinationPath>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <_ReswOutputFiles Include="@(_AllResxFiles->'$(_ResWDestinationPath)/%(ReswName).resw')" />
+ </ItemGroup>
+
+ </Target>
+
+ <Target Name="CopyResxFilesToReswFiles"
+ Condition="'$(BuildingUAPVertical)' == 'true'"
+ DependsOnTargets="CalculateResourcesFileNames"
+ Inputs="@(_AllResxFiles)"
+ Outputs="@(_ReswOutputFiles)" >
+
+ <Copy SourceFiles="@(_AllResxFiles)"
+ DestinationFiles="@(_ReswOutputFiles)"
+ SkipUnchangedFiles="true">
+ <Output TaskParameter="CopiedFiles" ItemName="FilesCreated" />
+ </Copy>
+
+ <!-- We need to touch the copied files so that the target that uses them can track the inputs and outputs with the copied timestamp -->
+ <Touch Files="@(FilesCreated)" />
+
+ </Target>
+
+ <PropertyGroup Condition="'$(StringResourcesPath)'!=''">
+ <CompileDependsOn>
+ NormalizeAssemblyName;
+ GenerateResourcesSource;
+ GenerateCommonSRSource;
+ $(CompileDependsOn);
+ </CompileDependsOn>
+ </PropertyGroup>
+
+ <Target Name="NormalizeAssemblyName" Condition="'$(StringResourcesPath)'!='' AND '$(OmitResources)'!='true'">
+ <NormalizeAssemblyName
+ AssemblyName="$(AssemblyName)" >
+ <Output TaskParameter="NormalizedAssemblyName" PropertyName="_NormalizedAssemblyName" />
+ </NormalizeAssemblyName>
+
+ <ItemGroup>
+ <!--
+ EmbeddedResource is defined outside the target and cannot be defined inside this target
+ we need to update logical name and ReswName after we normalize the assembly name.
+ -->
+ <EmbeddedResource Condition="'%(EmbeddedResource.LogicalName)'=='FxResources.$(AssemblyName).SR.resources'">
+ <LogicalName>FxResources.$(_NormalizedAssemblyName).SR.resources</LogicalName>
+ <ReswName Condition="'$(BuildingUAPVertical)' == 'true'">FxResources.$(_NormalizedAssemblyName).SR</ReswName>
+ </EmbeddedResource>
+ </ItemGroup>
+ </Target>
+
+ <Target Name="GenerateResourcesSource" DependsOnTargets="NormalizeAssemblyName"
+ Condition="'$(StringResourcesPath)'!='' AND '$(OmitResources)'!='true'"
+ Inputs="$(StringResourcesPath)"
+ Outputs="$(IntermediateResOutputFileFullPath)">
+
+ <GenerateResourcesCode
+ ResxFilePath="$(StringResourcesPath)"
+ OutputSourceFilePath="$(IntermediateResOutputFileFullPath)"
+ AssemblyName="$(_NormalizedAssemblyName)"
+ SRNamespace="$(GenerateResourcesSRNamespace)"
+ SRClassName="$(GenerateResourcesSRClassName)"
+ ResourcesNamespace="$(GenerateResourcesResourcesNamespace)"
+ ResourcesClassName="$(GenerateResourcesResourcesClassName)"
+ AsConstants="$(GenerateResourcesCodeAsConstants)"
+ AsEnum="$(GenerateResourcesCodeAsEnum)">
+ </GenerateResourcesCode>
+
+ <ItemGroup>
+ <!-- The following Compile element has to be included dynamically inside the Target otherwise intellisense will not work -->
+ <Compile Include="$(IntermediateResOutputFileFullPath)" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <FileWrites Include="$(IntermediateResOutputFileFullPath)" />
+ </ItemGroup>
+ </Target>
+
+ <Target Name="GenerateCommonSRSource"
+ Condition="'$(StringResourcesPath)'!='' AND '$(OmitResources)'!='true' AND '$(SkipCommonResourcesIncludes)'=='' AND '$(ShouldGenerateCommonSRFile)'=='true'"
+ Inputs="$(CommonSRSourceFile)"
+ Outputs="$(IntermediateCommonSRFileFullPath)">
+
+ <WriteLinesToFile File="$(IntermediateCommonSRFileFullPath)" Overwrite="true"
+ Lines="$([System.IO.File]::ReadAllText('$(CommonSRSourceFile)').Replace('#CUSTOM_SR_NAMESPACE#', '$(GenerateResourcesSRNamespace)').Replace('#CUSTOM_SR_CLASSNAME#', '$(GenerateResourcesSRClassName)'))" />
+
+ <PropertyGroup>
+ <DefineConstants Condition="'$(GenerateResourcesSRNamespace)' != ''">$(DefineConstants);CUSTOM_SR_NAMESPACE</DefineConstants>
+ <DefineConstants Condition="'$(GenerateResourcesSRClassName)' != ''">$(DefineConstants);CUSTOM_SR_CLASSNAME</DefineConstants>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Compile Include="$(IntermediateCommonSRFileFullPath)">
+ <Visible>true</Visible>
+ <Link>Resources/Common/SR$(ResourcesSourceFileExtension)</Link>
+ </Compile>
+ </ItemGroup>
+
+
+ <ItemGroup>
+ <FileWrites Include="$(IntermediateCommonSRFileFullPath)" />
+ </ItemGroup>
+ </Target>
+
+ <ItemGroup Condition="'$(StringResourcesPath)'!='' AND '$(OmitResources)'!='true'">
+ <EmbeddedResource Include="$(StringResourcesPath)">
+ <Visible>true</Visible>
+ <LogicalName>FxResources.$(AssemblyName).SR.resources</LogicalName>
+ <ReswName Condition="'$(BuildingUAPVertical)' == 'true'">FxResources.$(AssemblyName).SR</ReswName>
+ <!-- Set the Generator metadata so that VS triggers design-time build whenever the .resx file is saved -->
+ <Generator>MSBuild:GenerateResourcesSource</Generator>
+ </EmbeddedResource>
+ </ItemGroup>
+
+ <Choose>
+ <When Condition="Exists('$(StringResourcesPath)') AND '$(OmitResources)'!='true' AND '$(SkipCommonResourcesIncludes)'=='' AND '$(ShouldGenerateCommonSRFile)'==''">
+ <ItemGroup>
+ <Compile Include="$(CommonSRSourceFile)">
+ <Visible>true</Visible>
+ <Link>Resources/Common/SR$(ResourcesSourceFileExtension)</Link>
+ </Compile>
+ </ItemGroup>
+ </When>
+ </Choose>
+</Project>