aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiguel Costa <miguel.costa@qt.io>2023-12-20 15:33:18 +0100
committerMiguel Costa <miguel.costa@qt.io>2024-01-09 15:18:33 +0000
commitb6e902017fbdce55836fcf5ff16c1ef01f399824 (patch)
tree11a4d15c635f1c5548f707feba4e64f8fe649d44
parentd7635dbc90d2c6e19e7c5209b8a2faae91788a3c (diff)
Make buildtime properties available to any project
To add this feature to a project, add EvalProps.cs and import EvalProps.targets at the end of the project file. Change-Id: I8302df3859da8519dbc25f248b6996cdf7926085 Reviewed-by: Ali Can Demiralp <ali.demiralp@qt.io> Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r--EvalProps.cs (renamed from Tests/Test_QtMsBuild.Build/Props.cs)7
-rw-r--r--EvalProps.targets44
-rw-r--r--Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj39
-rw-r--r--vstools.sln1
4 files changed, 55 insertions, 36 deletions
diff --git a/Tests/Test_QtMsBuild.Build/Props.cs b/EvalProps.cs
index ba0329d8..f8d76399 100644
--- a/Tests/Test_QtMsBuild.Build/Props.cs
+++ b/EvalProps.cs
@@ -7,17 +7,18 @@ using System.Collections.Generic;
using System.Linq;
using System.IO;
-namespace QtVsTools.Test.QtMsBuild.Build
+namespace QtVsTools
{
public static class Properties
{
- static Dictionary<string, string> PropEval = File.ReadAllLines("PropEval.csv")
+ static Dictionary<string, string> PropEval = File.ReadAllLines("evalprops.csv")
.Select(x => x.Split(';'))
.ToDictionary(x => x.First(), x => string.Join(";", x.Skip(1)));
public static IReadOnlyDictionary<string, string> ValueOf => PropEval;
+ public static string Configuration => ValueOf["Configuration"];
public static string MSBuildToolsPath => ValueOf["MSBuildToolsPath"];
+ public static string SolutionDir => ValueOf["SolutionDir"];
public static string VsInstallRoot => ValueOf["VsInstallRoot"];
public static string VCTargetsPath => ValueOf["VCTargetsPath"];
- public static string SolutionDir => ValueOf["SolutionDir"];
}
}
diff --git a/EvalProps.targets b/EvalProps.targets
new file mode 100644
index 00000000..73ea011a
--- /dev/null
+++ b/EvalProps.targets
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+***************************************************************************************************
+ Copyright (C) 2023 The Qt Company Ltd.
+ SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+***************************************************************************************************
+-->
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <!--
+ /////////////////////////////////////////////////////////////////////////////////////////////////
+ // Export property evaluation
+ // -->
+ <PropertyGroup>
+ <PropEvalFileName Condition="'$(PropEvalFileName)' == ''">evalprops.csv</PropEvalFileName>
+ <PropEvalPath Condition="'$(PropEvalPath)' == ''">$(IntermediateOutputPath)$(PropEvalFileName)</PropEvalPath>
+ </PropertyGroup>
+ <Target Name="ExportPropertyEval" BeforeTargets="PrepareForBuild" Inputs="$(ProjectPath)" Outputs="$(PropEvalPath)">
+ <ItemGroup>
+ <PropEval Include="MSBuildToolsPath">
+ <Value>$(MSBuildToolsPath)</Value>
+ </PropEval>
+ <PropEval Include="VsInstallRoot">
+ <Value>$(VsInstallRoot)</Value>
+ </PropEval>
+ <PropEval Include="VCTargetsPath">
+ <Value>$(VCTargetsPath)</Value>
+ </PropEval>
+ <PropEval Include="SolutionDir">
+ <Value>$(SolutionDir)</Value>
+ </PropEval>
+ <PropEval Include="Configuration">
+ <Value>$(Configuration)</Value>
+ </PropEval>
+ </ItemGroup>
+ <WriteLinesToFile File="$(PropEvalPath)" Lines="@(PropEval->'%(Identity);%(Value)','%0D%0A')" Overwrite="true" />
+ <ItemGroup>
+ <PropEval Remove="@(PropEval)" />
+ <Content Include="$(PropEvalPath)">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <TargetPath>$(PropEvalFileName)</TargetPath>
+ </Content>
+ </ItemGroup>
+ </Target>
+</Project>
diff --git a/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj b/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj
index 75232854..5d2cf5a2 100644
--- a/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj
+++ b/Tests/Test_QtMsBuild.Build/Test_QtMsBuild.Build.csproj
@@ -107,7 +107,6 @@
<None Include="app.config" />
<Compile Include="TempProject.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
- <Compile Include="Props.cs" />
<Compile Include="Logger.cs" />
<Compile Include="MsBuild.cs" />
<Compile Include="Test_IntDir.cs" />
@@ -115,39 +114,13 @@
<Compile Include="Test_Eval.cs" />
<Compile Include="Test_Build.cs" />
</ItemGroup>
+ <ItemGroup>
+ <Compile Include="$(SolutionDir)\EvalProps.cs">
+ <Link>EvalProps.cs</Link>
+ </Compile>
+ </ItemGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Condition="Exists('$(SolutionDir)\transform.targets')" Project="$(SolutionDir)\transform.targets" />
- <!--
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Export property evaluation
- // -->
- <PropertyGroup>
- <PropEvalFileName Condition="'$(PropEvalFileName)' == ''">PropEval.csv</PropEvalFileName>
- <PropEvalPath Condition="'$(PropEvalPath)' == ''">$(IntermediateOutputPath)$(PropEvalFileName)</PropEvalPath>
- </PropertyGroup>
- <Target Name="ExportPropertyEval" BeforeTargets="PrepareForBuild" Inputs="$(ProjectPath)" Outputs="$(PropEvalPath)">
- <ItemGroup>
- <PropEval Include="MSBuildToolsPath">
- <Value>$(MSBuildToolsPath)</Value>
- </PropEval>
- <PropEval Include="VsInstallRoot">
- <Value>$(VsInstallRoot)</Value>
- </PropEval>
- <PropEval Include="VCTargetsPath">
- <Value>$(VCTargetsPath)</Value>
- </PropEval>
- <PropEval Include="SolutionDir">
- <Value>$(SolutionDir)</Value>
- </PropEval>
- </ItemGroup>
- <WriteLinesToFile File="$(PropEvalPath)" Lines="@(PropEval->'%(Identity);%(Value)','%0D%0A')" Overwrite="true" />
- <ItemGroup>
- <PropEval Remove="@(PropEval)" />
- <Content Include="$(PropEvalPath)">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
- <TargetPath>$(PropEvalFileName)</TargetPath>
- </Content>
- </ItemGroup>
- </Target>
+ <Import Condition="Exists('$(SolutionDir)\EvalProps.targets')" Project="$(SolutionDir)\EvalProps.targets" />
</Project> \ No newline at end of file
diff --git a/vstools.sln b/vstools.sln
index 669c2af2..1017287f 100644
--- a/vstools.sln
+++ b/vstools.sln
@@ -95,6 +95,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C7F47BF-D12B-46BA-934B-CDC9C462D116}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
+ evalprops.targets = evalprops.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test_QtMsBuild.Build", "Tests\Test_QtMsBuild.Build\Test_QtMsBuild.Build.csproj", "{D90720E3-0D5E-42A3-90DE-A5265EA22F80}"