Skip to content

Commit

Permalink
Merge pull request #550 from christianhelle/msbuild
Browse files Browse the repository at this point in the history
Add support for disabling telemetry from MSBuild task
  • Loading branch information
christianhelle authored Dec 8, 2024
2 parents d1cbaff + 4e88391 commit 87d396c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Refitter.MSBuild/Refitter.MSBuild.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<Project>

<Target Name="Refitter" BeforeTargets="BeforeBuild">
<RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)" />
<RefitterGenerateTask ProjectFileDirectory="$(MSBuildProjectDirectory)"
DisableLogging="$(RefitterNoLogging)"/>
<ItemGroup>
<Compile Include="**/*.cs" />
</ItemGroup>
Expand Down
13 changes: 11 additions & 2 deletions src/Refitter.MSBuild/RefitterGenerateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public class RefitterGenerateTask : MSBuildTask
{
public string ProjectFileDirectory { get; set; }

public bool DisableLogging { get; set; }

public override bool Execute()
{
TryLogCommandLine($"Starting {nameof(RefitterGenerateTask)}");
Expand Down Expand Up @@ -47,14 +49,21 @@ private void StartProcess(string file)
var packageFolder = Path.GetDirectoryName(assembly.Location);
var seperator = Path.DirectorySeparatorChar;
var refitterDll = $"{packageFolder}{seperator}..{seperator}refitter.dll";
TryLogCommandLine("Starting " + refitterDll);

var args = $"{refitterDll} --settings-file {file}";
if (DisableLogging)
{
args += " --no-logging";
}

TryLogCommandLine($"Starting dotnet {args}");

using var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"{refitterDll} --settings-file {file}",
Arguments = args,
WorkingDirectory = Path.GetDirectoryName(file)!,
RedirectStandardOutput = true,
RedirectStandardError = true,
Expand Down
5 changes: 3 additions & 2 deletions test/MSBuild/Refitter.MSBuild.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RefitterNoLogging>true</RefitterNoLogging>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,5 +14,5 @@
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.0" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
</ItemGroup>

</Project>

0 comments on commit 87d396c

Please sign in to comment.