Adding source generator to nuget package. (#403)

This commit is contained in:
Manodasan Wignarajah 2020-09-03 21:05:15 -07:00 коммит произвёл GitHub
Родитель 26b5f1ce71
Коммит 1c5bdfa3cd
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 32 добавлений и 3 удалений

Просмотреть файл

@ -5,12 +5,14 @@
<LangVersion>preview</LangVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<CsWinRTEnableLogging>true</CsWinRTEnableLogging>
<CsWinRTComponent>true</CsWinRTComponent>
<GeneratedFilesDir Condition="'$(GeneratedFilesDir)'==''">$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', '$(IntermediateOutputPath)', 'Generated Files'))</GeneratedFilesDir>
</PropertyGroup>
<ItemGroup>
<CompilerVisibleProperty Include="AssemblyName" />
<CompilerVisibleProperty Include="AssemblyVersion" />
<CompilerVisibleProperty Include="CsWinRTComponent" />
<CompilerVisibleProperty Include="CsWinRTEnableLogging" />
<CompilerVisibleProperty Include="GeneratedFilesDir" />
<ProjectReference Include="..\..\Projections\Windows\Windows.csproj" />

Просмотреть файл

@ -30,6 +30,16 @@ namespace Generator
return generatedFilesDir;
}
private static bool IsCsWinRTComponent(SourceGeneratorContext context)
{
if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTComponent", out var isCsWinRTComponentStr))
{
return bool.TryParse(isCsWinRTComponentStr, out var isCsWinRTComponent) && isCsWinRTComponent;
}
return false;
}
private string GetWinmdOutputFile(SourceGeneratorContext context)
{
return Path.Combine(GetGeneratedFilesDir(context), GetAssemblyName(context) + ".winmd");
@ -55,6 +65,11 @@ namespace Generator
public void Execute(SourceGeneratorContext context)
{
if (!IsCsWinRTComponent(context))
{
return;
}
Logger.Initialize(context);
try

Просмотреть файл

@ -7,8 +7,8 @@ namespace Generator
{
public static void Initialize(SourceGeneratorContext context)
{
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTEnableLogging", out var enableLogging);
if(enableLogging != null && bool.Parse(enableLogging))
context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.CsWinRTEnableLogging", out var enableLoggingStr);
if (enableLoggingStr != null && bool.TryParse(enableLoggingStr, out var enableLogging) && enableLogging)
{
string logFile = Path.Combine(SourceGenerator.GetGeneratedFilesDir(context), "log.txt");
fileLogger = File.CreateText(logFile);

Просмотреть файл

@ -128,4 +128,5 @@ set cswinrt_bin_dir=%~dp0_build\%cswinrt_platform%\%cswinrt_configuration%\cswin
set cswinrt_exe=%cswinrt_bin_dir%cswinrt.exe
set netstandard2_runtime=%~dp0WinRT.Runtime\bin\%cswinrt_configuration%\netstandard2.0\WinRT.Runtime.dll
set net5_runtime=%~dp0WinRT.Runtime\bin\%cswinrt_configuration%\net5.0\WinRT.Runtime.dll
.nuget\nuget pack nuget/Microsoft.Windows.CsWinRT.nuspec -Properties cswinrt_exe=%cswinrt_exe%;netstandard2_runtime=%netstandard2_runtime%;net5_runtime=%net5_runtime%;cswinrt_nuget_version=%cswinrt_version_string% -OutputDirectory %cswinrt_bin_dir% -NonInteractive -Verbosity Detailed -NoPackageAnalysis
set source_generator=%~dp0Authoring\WinRT.SourceGenerator\bin\%cswinrt_configuration%\netstandard2.0\WinRT.SourceGenerator.dll
.nuget\nuget pack nuget/Microsoft.Windows.CsWinRT.nuspec -Properties cswinrt_exe=%cswinrt_exe%;netstandard2_runtime=%netstandard2_runtime%;net5_runtime=%net5_runtime%;source_generator=%source_generator%;cswinrt_nuget_version=%cswinrt_version_string% -OutputDirectory %cswinrt_bin_dir% -NonInteractive -Verbosity Detailed -NoPackageAnalysis

Просмотреть файл

@ -27,5 +27,6 @@
<file src="readme.txt"/>
<file src="$netstandard2_runtime$" target="lib\netstandard2.0\"/>
<file src="$net5_runtime$" target="lib\net5.0\"/>
<file src="$source_generator$" target="analyzers\dotnet\cs\"/>
</files>
</package>

Просмотреть файл

@ -8,6 +8,16 @@ Copyright (C) Microsoft Corporation. All rights reserved.
<PropertyGroup>
<CsWinRTPath Condition="'$(CsWinRTPath)'==''">$([MSBuild]::NormalizeDirectory('$(MSBuildThisFileDirectory)', '..'))</CsWinRTPath>
<CsWinRTExe>$(CsWinRTPath)cswinrt.exe</CsWinRTExe>
<AllowUnsafeBlocks Condition="$(CsWinRTComponent)==true">true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup Condition="$(CsWinRTComponent)==true">
<CompilerVisibleProperty Include="AssemblyName" />
<CompilerVisibleProperty Include="AssemblyVersion" />
<CompilerVisibleProperty Include="CsWinRTComponent" />
<CompilerVisibleProperty Include="CsWinRTEnableLogging" />
<CompilerVisibleProperty Include="GeneratedFilesDir" />
<CompilerVisibleProperty Include="CsWinRTExe" />
</ItemGroup>
</Project>