Skip to content

Commit 55bb76b

Browse files
Add nowarn for NU1903 (#44028)
1 parent e6060a1 commit 55bb76b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.IO;
7+
using Microsoft.Build.Framework;
8+
using Microsoft.Build.Utilities;
9+
10+
namespace Microsoft.DotNet.UnifiedBuild.Tasks
11+
{
12+
public class ReplaceTextInFile : Task
13+
{
14+
[Required]
15+
public string InputFile { get; set; }
16+
17+
[Required]
18+
public string OldText { get; set; }
19+
20+
[Required]
21+
public string NewText { get; set; }
22+
23+
24+
public override bool Execute()
25+
{
26+
string fileContents = File.ReadAllText(InputFile);
27+
string newLineChars = FileUtilities.DetectNewLineChars(fileContents);
28+
29+
fileContents = fileContents.Replace(OldText, NewText);
30+
31+
File.WriteAllText(InputFile, FileUtilities.NormalizeNewLineChars(fileContents, newLineChars));
32+
33+
return true;
34+
}
35+
}
36+
}

src/SourceBuild/content/repo-projects/Directory.Build.targets

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,36 @@
3535
<ProdConManifestFile>$(PackageReportDir)prodcon-build.xml</ProdConManifestFile>
3636
</PropertyGroup>
3737

38+
<UsingTask TaskName="Microsoft.DotNet.UnifiedBuild.Tasks.ReplaceTextInFile" AssemblyFile="$(MicrosoftDotNetUnifiedBuildTasksAssembly)" TaskFactory="TaskHostFactory" />
39+
<Target Name="AddNoWarns"
40+
Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') OR EXISTS('$(ProjectDirectory)src/Directory.Build.props') "
41+
Inputs="$(MSBuildProjectFullPath)"
42+
Outputs="$(RepoCompletedSemaphorePath)AddNoWarns.complete" >
43+
44+
<!-- Don't warn on warnings that can be generated in source-build
45+
but not necessarily in repo builds.
46+
NU1603 - See https://github.com/dotnet/source-build/issues/2766.
47+
NU5104 - During preview builds, some packages have pre-release versions.
48+
Some repos with stable versions may need to uptake these packages
49+
with pre-release versions because of PVP when building with
50+
source-build. -->
51+
<PropertyGroup>
52+
<OldText><![CDATA[</Project>]]></OldText>
53+
<NewText>
54+
<![CDATA[ <PropertyGroup>
55+
<NoWarn>%24(NoWarn);NU1903;$(RepoNoWarns)</NoWarn>
56+
</PropertyGroup>
57+
</Project>]]>
58+
</NewText>
59+
60+
<DirectoryBuildPropsFile Condition=" EXISTS('$(ProjectDirectory)Directory.Build.props') ">$(ProjectDirectory)Directory.Build.props</DirectoryBuildPropsFile>
61+
<DirectoryBuildPropsFile Condition=" '$(DirectoryBuildPropsFile)' == '' AND EXISTS('$(ProjectDirectory)src/Directory.Build.props') ">$(ProjectDirectory)src/Directory.Build.props</DirectoryBuildPropsFile>
62+
</PropertyGroup>
63+
<ReplaceTextInFile InputFile="$(DirectoryBuildPropsFile)"
64+
OldText="$(OldText)"
65+
NewText="$(NewText)" />
66+
</Target>
67+
3868
<!-- Returns the repository references of this project and all the projects this project references, recursively -->
3969
<Target Name="GetTransitiveRepositoryReferences" Returns="@(TransitiveRepositoryReference)">
4070
<ItemGroup>
@@ -392,6 +422,7 @@
392422
Outputs="$(BaseIntermediateOutputPath)Build.complete"
393423
Condition="'$(BuildCommand)' != ''"
394424
DependsOnTargets="BuildRepoReferences;
425+
AddNoWarns;
395426
UpdateNuGetConfig;
396427
UpdateGlobalJsonVersions;
397428
UpdateEngCommonFiles;

0 commit comments

Comments
 (0)