Skip to content

Commit

Permalink
Parameterize Product details
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinRansom committed Jan 4, 2020
1 parent eee78e9 commit c8507f3
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 89 deletions.
56 changes: 54 additions & 2 deletions FSharpBuild.Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
<Project>

<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
<Import Project="eng\targets\Imports.targets" />
<Import Project="eng\targets\NuGet.targets" />
<Import Project="eng\targets\NGenBinaries.targets" />
<Import Project="FSharp.Profiles.props" />

<Target Name="_GenerateBuildPropertiesFile"
Outputs="$(IntermediateOutputPath)buildproperties.fs"
BeforeTargets="BeforeBuild"
Condition="'$(Language)'=='F#'">

<ItemGroup>
<_BuildPropertyLines Remove="@(_BuildPropertyLines)" />
<_BuildPropertyLines Include="// &lt;auto-generated &gt;" />
<_BuildPropertyLines Include="// &lt;Generated by the FSharp WriteCodeFragment class./&gt;" />
<_BuildPropertyLines Include="// &lt;/auto-generated/&gt;" />
<_BuildPropertyLines Include="//" />
<_BuildPropertyLines Include="module internal FSharp.BuildProperties" />
<_BuildPropertyLines Include="let fsProductVersion = &quot;$(FSPRODUCTVERSION)&quot;" />
<_BuildPropertyLines Include="let fsLanguageVersion = &quot;$(FSLANGUAGEVERSION)&quot;" />
</ItemGroup>

<MakeDir
Directories="$(IntermediateOutputPath)"
Condition="!Exists('$(IntermediateOutputPath)')" />
<WriteLinesToFile File="$(IntermediateOutputPath)buildproperties.fs" Lines="@(_BuildPropertyLines)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<!-- Make sure it will get cleaned -->
<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)buildproperties.fs" />
<CompileBefore Include="$(IntermediateOutputPath)buildproperties.fs" />
</ItemGroup>
</Target>

<Target Name="NoneSubstituteTextFiles"
Inputs="@(NoneSubstituteText)"
Outputs="@(NoneSubstituteText->'$(IntermediateOutputPath)%(Filename)%(Extension)')"
BeforeTargets="AssignTargetPaths;BeforeBuild">
BeforeTargets="AssignTargetPaths;BeforeBuild;GenerateFSharpTextResources">

<PropertyGroup>
<__TargetFilePath>@(NoneSubstituteText->'$(IntermediateOutputPath)%(Filename)%(Extension)')</__TargetFilePath>
Expand All @@ -27,7 +56,7 @@
<WriteLinesToFile File="$(__TargetFilePath)" Lines="$(_ReplacementText)" Overwrite="true" WriteOnlyWhenDifferent="true" />

<!-- Make sure it will get cleaned -->
<ItemGroup >
<ItemGroup>
<None Include="$(__TargetFilePath)" CopyToOutputDirectory="$(_CopyToOutputDirectory)" />
<FileWrites Include="$(__TargetFilePath)" Condition="'$(__TargetFileName)' != 'App.config'" />
</ItemGroup>
Expand Down Expand Up @@ -61,4 +90,27 @@
</ItemGroup>
</Target>

<Target Name="BeforeResGen"
Inputs="@(EmbeddedResource->'$(IntermediateOutputPath)%(Filename)%(Extension)')"
Outputs="@(EmbeddedResource->'$(IntermediateOutputPath)resources\%(Filename)%(Extension)')"
DependsOnTargets="CopyVsixResources"
Condition="'$(Configuration)' != 'Proto' and '$(Language)'=='F#'">
<SubstituteText EmbeddedResources="@(EmbeddedResource)">
<Output TaskParameter="CopiedFiles" ItemName="CopiedFiles" />
</SubstituteText>

<Message Text="CopiedFiles: '@(CopiedFiles)'" />
<ItemGroup>
<EmbeddedResource Remove="@(EmbeddedResource)"/>
<EmbeddedResource Include="@(CopiedFiles)"/>
</ItemGroup>

<MakeDir Directories="$(IntermediateOutputPath)" Condition="!Exists('$(IntermediateOutputPath)')" />
<MakeDir Directories="$(IntermediateOutputPath)resources\" Condition="!Exists('$(IntermediateOutputPath)resources\')" />
</Target>

<Target Name="CopyVsixResources">
<Copy SourceFiles="@(CopyVsixResources)" DestinationFolder="$(IntermediateOutputPath)\resources\Resources" />
</Target>

</Project>
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Build/FSharp.Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<Compile Include="FSharpEmbedResXSource.fs" />
<Compile Include="WriteCodeFragment.fs" />
<Compile Include="CreateFSharpManifestResourceName.fs" />
<Compile Include="SubstituteText.fs" />
<None Include="Microsoft.FSharp.Targets" CopyToOutputDirectory="PreserveNewest" />
<None Include="Microsoft.Portable.FSharp.Targets" CopyToOutputDirectory="PreserveNewest" />
<None Include="Microsoft.FSharp.NetSdk.targets" CopyToOutputDirectory="PreserveNewest" />
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Build/Microsoft.FSharp.Targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ this file.
<UsingTask TaskName="CreateFSharpManifestResourceName" AssemblyFile="$(FSharpBuildAssemblyFile)" />
<UsingTask TaskName="WriteCodeFragment" AssemblyFile="$(FSharpBuildAssemblyFile)" />
<UsingTask TaskName="FSharpPlatformInformation" AssemblyFile="$(FSharpBuildAssemblyFile)" />
<UsingTask TaskName="SubstituteText" AssemblyFile="$(FSharpBuildAssemblyFile)" />

<PropertyGroup>
<ImportByWildcardBeforeMicrosoftFSharpTargets Condition="'$(ImportByWildcardBeforeMicrosoftFSharpTargets)' == ''">true</ImportByWildcardBeforeMicrosoftFSharpTargets>
Expand Down
92 changes: 92 additions & 0 deletions src/fsharp/FSharp.Build/SubstituteText.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace FSharp.Build

open System
open System.Collections
open System.IO
open Microsoft.Build.Framework
open Microsoft.Build.Utilities

type SubstituteText () =

let mutable _buildEngine : IBuildEngine = null
let mutable _hostObject : ITaskHost = null

let mutable copiedFiles = new ResizeArray<ITaskItem>()
let mutable embeddedResources : ITaskItem[] = [||]

[<Required>]
member this.EmbeddedResources
with get() = embeddedResources
and set(value) = embeddedResources <- value

[<Output>]
member this.CopiedFiles
with get() = copiedFiles.ToArray()

interface ITask with
member this.BuildEngine
with get() = _buildEngine
and set(value) = _buildEngine <- value

member this.HostObject
with get() = _hostObject
and set(value) = _hostObject <- value

member this.Execute() =
copiedFiles.Clear()
if not(isNull embeddedResources) then
for item in embeddedResources do
// Update ITaskItem metadata to point to new location
let sourcePath = item.GetMetadata("FullPath")

let pattern1 = item.GetMetadata("Pattern1")
let pattern2 = item.GetMetadata("Pattern2")

// Is there any replacement to do?
if not (String.IsNullOrWhiteSpace(pattern1) && String.IsNullOrWhiteSpace(pattern2)) then
if not(String.IsNullOrWhiteSpace(sourcePath)) then
try
let getTargetPathFrom key =
let md = item.GetMetadata(key)
let path = Path.GetDirectoryName(md)
let filename = Path.GetFileName(md)
let target = Path.Combine(path, @"..\resources", filename)
target

// Copy from the location specified in Identity
let sourcePath=item.GetMetadata("Identity")

// Copy to the location specified in TargetPath unless no TargetPath is provided, then use Identity
let targetPath=
let identityPath = getTargetPathFrom "Identity"
let intermediateTargetPath = item.GetMetadata("IntermediateTargetPath")
if not (String.IsNullOrWhiteSpace(intermediateTargetPath)) then
let filename = Path.GetFileName(identityPath)
let target = Path.Combine(intermediateTargetPath, filename)
target
else
identityPath

item.ItemSpec <- targetPath

// Transform file
let mutable contents = File.ReadAllText(sourcePath)
if not (String.IsNullOrWhiteSpace(pattern1)) then
let replacement = item.GetMetadata("Replacement1")
contents <- contents.Replace(pattern1, replacement)
if not (String.IsNullOrWhiteSpace(pattern2)) then
let replacement = item.GetMetadata("Replacement2")
contents <- contents.Replace(pattern2, replacement)

let directory = Path.GetDirectoryName(targetPath)
if not(Directory.Exists(directory)) then
Directory.CreateDirectory(directory) |>ignore

File.WriteAllText(targetPath, contents)
with
| _ -> ()

copiedFiles.Add(item)
true
2 changes: 1 addition & 1 deletion vsintegration/Vsix/RegisterFsharpPackage.pkgdef
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"1"="{92EF0900-2251-11D2-B72E-0000F87572EF}"

[$RootKey$\Packages\{91a04a73-4f2c-4e7c-ad38-c1a68e7da05c}]
"ProductVersion"="10.4"
"ProductVersion"="{{FSProductVersion}}"
"ProductName"="Visual F#"
"CompanyName"="Microsoft Corp."

Expand Down
15 changes: 10 additions & 5 deletions vsintegration/Vsix/VisualFSharpFull/VisualFSharpFull.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@
<None Include="Source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
<Content Include="..\RegisterFsharpPackage.pkgdef">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
<Link>RegisterFsharpPackage.pkgdef</Link>
</Content>

<NoneSubstituteText Include="..\RegisterFsharpPackage.pkgdef" CopyToOutputDirectory="PreserveNewest">
<TargetFileName>RegisterFsharpPackage.pkgdef</TargetFileName>
<Pattern1>{{FSProductVersion}}</Pattern1>
<Replacement1>$(FSProductVersion)</Replacement1>
<Pattern2>{{FSLanguageVersion}}</Pattern2>
<Replacement2>$(FSLanguageVersion)</Replacement2>
</NoneSubstituteText>

<Content Include="$(FSharpSourcesRoot)\..\License.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>License.txt</Link>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>

<Content Include="$(NuGetPackageRoot)\Microsoft.VisualFSharp.Type.Providers.Redist\$(MicrosoftVisualFSharpTypeProvidersRedistVersion)\content\$(FSharpDataTypeProvidersVersion)\FSharp.Data.TypeProviders.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>FSharp.Data.TypeProviders.dll</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@
<ResourceName>Menus.ctmenu</ResourceName>
<SubType>Designer</SubType>
</VSCTCompile>

<!-- Copy resx file and transform product/language version -->
<CopyVsixResources Include="Resources/**" />
<EmbeddedResource Include="VSPackage.resx">
<GenerateSource>true</GenerateSource>
<GeneratedModuleName>Microsoft.VisualStudio.FSharp.ProjectSystem.FSharpSR</GeneratedModuleName>
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
<SubType>Designer</SubType>
<IntermediateTargetPath>$(IntermediateOutputPath)resources\</IntermediateTargetPath>
<Pattern1>{{FSProductVersion}}</Pattern1>
<Replacement1>$(FSProductVersion)</Replacement1>
<Pattern2>{{FSLanguageVersion}}</Pattern2>
<Replacement2>$(FSLanguageVersion)</Replacement2>
</EmbeddedResource>

<Compile Include="ProjectPrelude.fs" />
<Compile Include="WaitDialog.fs" />
<Compile Include="MSBuildUtilities.fs" />
Expand Down
6 changes: 3 additions & 3 deletions vsintegration/src/FSharp.ProjectSystem.FSharp/VSPackage.resx
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,10 @@
<value>Customizes the environment to maximize code editor screen space and improve the visibility of F# commands and tool windows.</value>
</data>
<data name="ProductDetails" xml:space="preserve">
<value>Microsoft Visual F# Tools 10.4 for F# 4.6</value>
<value>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</value>
</data>
<data name="9002" xml:space="preserve">
<value>Microsoft Visual F# Tools 10.4 for F# 4.6</value>
<value>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</value>
</data>
<data name="ProductID" xml:space="preserve">
<value>1.0</value>
Expand All @@ -476,7 +476,7 @@
<value>Microsoft Visual F# Tools</value>
</data>
<data name="9001" xml:space="preserve">
<value>Visual F# Tools 10.4 for F# 4.6</value>
<value>Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</value>
</data>
<data name="9027" xml:space="preserve">
<value>F# Interactive</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@
<note />
</trans-unit>
<trans-unit id="ProductDetails">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Nástroje Microsoft Visual F# 10.4 pro F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Nástroje Microsoft Visual F# {{FSProductVersion}} pro F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9002">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Nástroje Microsoft Visual F# 10.4 pro F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Nástroje Microsoft Visual F# {{FSProductVersion}} pro F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="ProductID">
Expand All @@ -453,8 +453,8 @@
<note />
</trans-unit>
<trans-unit id="9001">
<source>Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Nástroje Visual F# 10.4 pro F# 4.6</target>
<source>Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Nástroje Visual F# {{FSProductVersion}} pro F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9027">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@
<note />
</trans-unit>
<trans-unit id="ProductDetails">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Microsoft Visual F# Tools 10.4 für f# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Microsoft Visual F# Tools {{FSProductVersion}} für f# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9002">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Microsoft Visual F# Tools 10.4 für f# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Microsoft Visual F# Tools {{FSProductVersion}} für f# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="ProductID">
Expand All @@ -453,8 +453,8 @@
<note />
</trans-unit>
<trans-unit id="9001">
<source>Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Visual F# Tools 10.4 für F# 4.6</target>
<source>Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Visual F# Tools {{FSProductVersion}} für F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9027">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@
<note />
</trans-unit>
<trans-unit id="ProductDetails">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Herramientas de Microsoft Visual F# 10.4 para F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Herramientas de Microsoft Visual F# {{FSProductVersion}} para F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9002">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Herramientas de Microsoft Visual F# 10.4 para F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Herramientas de Microsoft Visual F# {{FSProductVersion}} para F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="ProductID">
Expand All @@ -453,8 +453,8 @@
<note />
</trans-unit>
<trans-unit id="9001">
<source>Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Visual F# Tools 10.4 para F# 4.6</target>
<source>Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Visual F# Tools {{FSProductVersion}} para F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9027">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,13 @@
<note />
</trans-unit>
<trans-unit id="ProductDetails">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Microsoft Visual F# Tools 10.4 pour F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Microsoft Visual F# Tools {{FSProductVersion}} pour F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9002">
<source>Microsoft Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Microsoft Visual F# Tools 10.4 pour F# 4.6</target>
<source>Microsoft Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Microsoft Visual F# Tools {{FSProductVersion}} pour F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="ProductID">
Expand All @@ -453,8 +453,8 @@
<note />
</trans-unit>
<trans-unit id="9001">
<source>Visual F# Tools 10.4 for F# 4.6</source>
<target state="translated">Visual F# Tools 10.4 pour F# 4.6</target>
<source>Visual F# Tools {{FSProductVersion}} for F# {{FSLanguageVersion}}</source>
<target state="needs-review-translation">Visual F# Tools {{FSProductVersion}} pour F# {{FSLanguageVersion}}</target>
<note />
</trans-unit>
<trans-unit id="9027">
Expand Down
Loading

0 comments on commit c8507f3

Please sign in to comment.