Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[main] Add nowarn for NU1903 #44078

Merged
merged 2 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Microsoft.DotNet.UnifiedBuild.Tasks
{
public class ReplaceTextInFile : Task
{
[Required]
public string InputFile { get; set; }

[Required]
public string OldText { get; set; }

[Required]
public string NewText { get; set; }


public override bool Execute()
{
string fileContents = File.ReadAllText(InputFile);
string newLineChars = FileUtilities.DetectNewLineChars(fileContents);

fileContents = fileContents.Replace(OldText, NewText);

File.WriteAllText(InputFile, FileUtilities.NormalizeNewLineChars(fileContents, newLineChars));

return true;
}
}
}
31 changes: 31 additions & 0 deletions src/SourceBuild/content/repo-projects/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@
<ProdConManifestFile>$(PackageReportDir)prodcon-build.xml</ProdConManifestFile>
</PropertyGroup>

<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.ReplaceTextInFile" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
<Target Name="AddNoWarns"
Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') OR EXISTS('$(ProjectDirectory)src/Directory.Build.props') "
Inputs="$(MSBuildProjectFullPath)"
Outputs="$(RepoCompletedSemaphorePath)AddNoWarns.complete" >

<!-- Don't warn on warnings that can be generated in source-build
but not necessarily in repo builds.
NU1603 - See https://github.com/dotnet/source-build/issues/2766.
NU5104 - During preview builds, some packages have pre-release versions.
Some repos with stable versions may need to uptake these packages
with pre-release versions because of PVP when building with
source-build. -->
<PropertyGroup>
<OldText><![CDATA[</Project>]]></OldText>
<NewText>
<![CDATA[ <PropertyGroup>
<NoWarn>%24(NoWarn);NU1903;$(RepoNoWarns)</NoWarn>
</PropertyGroup>
</Project>]]>
</NewText>

<DirectoryBuildPropsFile Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') ">$(ProjectDirectory)Directory.Build.props</DirectoryBuildPropsFile>
<DirectoryBuildPropsFile Condition=" '$(DirectoryBuildPropsFile)' == '' AND EXISTS('$(ProjectDirectory)src/Directory.Build.props') ">$(ProjectDirectory)src/Directory.Build.props</DirectoryBuildPropsFile>
</PropertyGroup>
<ReplaceTextInFile InputFile="$(DirectoryBuildPropsFile)"
OldText="$(OldText)"
NewText="$(NewText)" />
</Target>

<!-- Returns the repository references of this project and all the projects this project references, recursively -->
<Target Name="GetTransitiveRepositoryReferences" Returns="@(TransitiveRepositoryReference)">
<ItemGroup>
Expand Down Expand Up @@ -392,6 +422,7 @@
Outputs="$(BaseIntermediateOutputPath)Build.complete"
Condition="'$(BuildCommand)' != ''"
DependsOnTargets="BuildRepoReferences;
AddNoWarns;
UpdateNuGetConfig;
UpdateGlobalJsonVersions;
UpdateEngCommonFiles;
Expand Down