Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/NuGet.BuildTasks.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnkit Mishra <anmishr@microsoft.com>2018-05-23 00:08:20 +0300
committerAnkit Mishra <anmishr@microsoft.com>2018-05-23 00:13:23 +0300
commit5be6895a10d0a7e2193757dd3ec7426567f31274 (patch)
treefd2030359783fc1c947a1d14fee7a1f9881d64b8
parent67d7e5768d6ce34f26530d04d1ba40e5f2dab22f (diff)
Adding tests
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/Helpers/TempRoot.cs4
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj20
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs5
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/ProjectReferences/Resources.Designer.cs2
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs211
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/app.config4
-rw-r--r--src/Microsoft.NuGet.Build.Tasks.Tests/project.json8
-rw-r--r--src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs24
-rw-r--r--src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs4
-rw-r--r--src/Microsoft.NuGet.Build.Tasks/Strings.resx2
10 files changed, 242 insertions, 42 deletions
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Helpers/TempRoot.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/Helpers/TempRoot.cs
index 7cda580..004171b 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/Helpers/TempRoot.cs
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Helpers/TempRoot.cs
@@ -54,9 +54,9 @@ namespace Microsoft.NuGet.Build.Tasks.Tests.Helpers
return dir;
}
- public TempFile CreateFile(TempRoot root, string prefix = null, string extension = null, string directory = null, [CallerFilePath]string callerSourcePath = null, [CallerLineNumber]int callerLineNumber = 0)
+ public TempFile CreateFile(string prefix = null, string extension = null, string directory = null, [CallerFilePath]string callerSourcePath = null, [CallerLineNumber]int callerLineNumber = 0)
{
- return AddFile(new DisposableFile(root, prefix, extension, directory, callerSourcePath, callerLineNumber));
+ return AddFile(new DisposableFile(this, prefix, extension, directory, callerSourcePath, callerLineNumber));
}
public DisposableFile AddFile(DisposableFile file)
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj b/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj
index 342af76..270ee06 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Microsoft.NuGet.Build.Tasks.Tests.csproj
@@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Microsoft.NuGet.Build.Tasks.Tests</RootNamespace>
<AssemblyName>Microsoft.NuGet.Build.Tasks.Tests</AssemblyName>
- <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<SignAssembly>true</SignAssembly>
@@ -72,7 +72,9 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
- <None Include="app.config" />
+ <None Include="app.config">
+ <SubType>Designer</SubType>
+ </None>
<None Include="Json\analyzers.json" />
<None Include="Json\FluentAssertions.lock.json" />
<None Include="Json\FluentAssertionsAndWin10.lock.json" />
@@ -83,7 +85,6 @@
<None Include="Json\Win10.Edm.json" />
<None Include="Json\Win10.json" />
<None Include="Json\Win10.xunit.json" />
- <None Include="project.json" />
<None Include="Json\ProjectDependency.assets.json" />
<None Include="ProjectReferences\LockFileMissingMSBuildProjectThatProvidesAssets.json" />
<None Include="ProjectReferences\LockFileWithCSProjReference.json" />
@@ -101,6 +102,19 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="NuGet.ProjectModel">
+ <Version>4.7.0</Version>
+ </PackageReference>
+ <PackageReference Include="xunit">
+ <Version>2.3.1</Version>
+ </PackageReference>
+ <PackageReference Include="xunit.runner.visualstudio">
+ <Version>2.3.1</Version>
+ <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
+ <PrivateAssets>all</PrivateAssets>
+ </PackageReference>
+ </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs
index f31e9d0..3a271d3 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/NuGetTestHelpers.cs
@@ -7,8 +7,6 @@ using System.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
-using Microsoft.NuGet.Build.Tasks;
-using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
using Microsoft.NuGet.Build.Tasks.Tests.Helpers;
@@ -21,6 +19,7 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
string projectLockJsonFileContents,
string targetMoniker,
string runtimeIdentifier,
+ bool isLockFileProjectJsonBased = true,
string projectLanguage = null,
bool allowFallbackOnTargetSelection = false,
TryGetRuntimeVersion tryGetRuntimeVersion = null,
@@ -33,7 +32,7 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
{
var projectDirectory = rootDirectory.CreateDirectory();
- var projectLockJsonFile = projectDirectory.CreateFile("project.lock.json");
+ var projectLockJsonFile = projectDirectory.CreateFile(isLockFileProjectJsonBased ? "project.lock.json" : "project.assets.json");
projectLockJsonFile.WriteAllText(projectLockJsonFileContents);
if (projectJsonFileContents != null)
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/ProjectReferences/Resources.Designer.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/ProjectReferences/Resources.Designer.cs
index 1af74df..2d185d8 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/ProjectReferences/Resources.Designer.cs
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/ProjectReferences/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace Microsoft.NuGet.Build.Tasks.Tests.ProjectReferences {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs
index 2a8e2d2..d8a3404 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/ReferenceResolutionTests.cs
@@ -2,9 +2,16 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
+using System.Collections.Generic;
+using System.Diagnostics;
using System.IO;
using System.Linq;
-using Microsoft.NuGet.Build.Tasks;
+using Microsoft.NuGet.Build.Tasks.Tests.Helpers;
+using NuGet.Frameworks;
+using NuGet.LibraryModel;
+using NuGet.Packaging.Core;
+using NuGet.ProjectModel;
+using NuGet.Versioning;
using Xunit;
namespace Microsoft.NuGet.Build.Tasks.Tests
@@ -108,7 +115,45 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
}
[Fact]
- public static void TestReferenceResolutionWithMissingTargetMonikerAndNoFallback()
+ public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackInProjectCsproj()
+ {
+ var lockFile = GenerateLockFileWithTarget();
+
+ using (var tempRoot = new TempRoot())
+ using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
+ {
+ new LockFileFormat().Write(disposableFile.Path, lockFile);
+
+ var exception = Assert.Throws<ExceptionFromResource>(() =>
+ NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
+ File.ReadAllText(disposableFile.Path),
+ targetMoniker: ".NETFramework,Version=v4.5",
+ runtimeIdentifier: "missing-runtime-identifier",
+ allowFallbackOnTargetSelection: false,
+ isLockFileProjectJsonBased: false));
+
+ Assert.Equal(nameof(Strings.MissingRuntimeIdentifierInCsproj), exception.ResourceName);
+ Assert.Equal(new[] { "missing-runtime-identifier", "missing-runtime-identifier" }, exception.MessageArgs);
+ }
+ }
+
+ [Fact]
+ public static void TestReferenceResolutionWithMissingRuntimeIDAndNoFallbackAndNoRuntimesSectionInProjectCsproj()
+ {
+ var exception = Assert.Throws<ExceptionFromResource>(() =>
+ NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
+ Json.Json.Win10,
+ targetMoniker: ".NETCore,Version=v5.0",
+ runtimeIdentifier: "missing-runtime-identifier",
+ allowFallbackOnTargetSelection: false,
+ projectJsonFileContents: "{ }"));
+
+ Assert.Equal(nameof(Strings.MissingRuntimesSectionInProjectJson), exception.ResourceName);
+ Assert.Equal(new[] { "\"runtimes\": { \"missing-runtime-identifier\": { } }" }, exception.MessageArgs);
+ }
+
+ [Fact]
+ public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallback()
{
var exception = Assert.Throws<ExceptionFromResource>(() =>
NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
@@ -122,6 +167,29 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
}
[Fact]
+ public static void TestReferenceResolutionWithMissingTargetFrameworkAndNoFallbackInProjectCsproj()
+ {
+ var lockFile = GenerateLockFileWithoutTarget();
+
+ using (var tempRoot = new TempRoot())
+ using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
+ {
+ new LockFileFormat().Write(disposableFile.Path, lockFile);
+
+ var exception = Assert.Throws<ExceptionFromResource>(() =>
+ NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
+ File.ReadAllText(disposableFile.Path),
+ targetMoniker: "Missing,Version=1.0",
+ runtimeIdentifier: "missing-runtime-identifier",
+ allowFallbackOnTargetSelection: false,
+ isLockFileProjectJsonBased: false));
+
+ Assert.Equal(nameof(Strings.MissingFrameworkInCsproj), exception.ResourceName);
+ Assert.Equal(new[] { "Missing,Version=1.0" }, exception.MessageArgs);
+ }
+ }
+
+ [Fact]
public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallback()
{
var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
@@ -136,6 +204,53 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
}
[Fact]
+ public static void TestReferenceResolutionWithMissingTargetFrameworkAndFallbackInProjectCsproj()
+ {
+ var lockFile = GenerateLockFileWithTarget();
+
+ using (var tempRoot = new TempRoot())
+ using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
+ {
+ new LockFileFormat().Write(disposableFile.Path, lockFile);
+
+ var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
+ File.ReadAllText(disposableFile.Path),
+ targetMoniker: "MissingFrameworkMoniker,Version=v42.0",
+ runtimeIdentifier: "",
+ allowFallbackOnTargetSelection: true,
+ isLockFileProjectJsonBased: false);
+
+ // We should still have references. Since we have no runtime ID, we should have no copy local items
+ AssertHelpers.AssertCountOf(1, result.References);
+ AssertHelpers.AssertCountOf(0, result.CopyLocalItems);
+ }
+ }
+
+ [Theory]
+ [InlineData(true, nameof(Strings.NoTargetsInLockFileForProjectJson))]
+ [InlineData(false, nameof(Strings.NoTargetsInLockFileForCsproj))]
+ public static void TestReferenceResolutionWithMissingTargets(bool isProjectJsonBased, string errorResourceName)
+ {
+ var lockFile = GenerateLockFileWithoutTarget();
+
+ using (var tempRoot = new TempRoot())
+ using (var disposableFile = new DisposableFile(tempRoot.CreateFile(extension: "assets.json").Path))
+ {
+ new LockFileFormat().Write(disposableFile.Path, lockFile);
+
+ var exception = Assert.Throws<ExceptionFromResource>(() =>
+ NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
+ File.ReadAllText(disposableFile.Path),
+ targetMoniker: "MissingFrameworkMoniker,Version=v42.0",
+ runtimeIdentifier: "",
+ allowFallbackOnTargetSelection: true,
+ isLockFileProjectJsonBased: isProjectJsonBased));
+
+ Assert.Equal(errorResourceName, exception.ResourceName);
+ }
+ }
+
+ [Fact]
public static void TestReferenceResolutionWithNoRuntimeID()
{
var result = NuGetTestHelpers.ResolvePackagesWithJsonFileContents(
@@ -270,9 +385,9 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
var key = ResolveNuGetPackageAssets.NuGetIsFrameworkReference;
var values = result.References.Select(r => r.GetMetadata(key));
-
+
Assert.All(result.References, r => Assert.Contains(key, r.MetadataNames.Cast<string>()));
- Assert.All(values, v => Assert.Contains(v, new [] { "true", "false" }));
+ Assert.All(values, v => Assert.Contains(v, new[] { "true", "false" }));
}
[Fact]
@@ -312,8 +427,8 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
targetMoniker: ".NETCore,Version=v5.0",
runtimeIdentifier: "win10-x86",
tryGetRuntimeVersion: tryGetRuntimeVersion);
-
- var winmd = result.CopyLocalItems.FirstOrDefault(c =>
+
+ var winmd = result.CopyLocalItems.FirstOrDefault(c =>
Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(winmd);
@@ -321,7 +436,7 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
Assert.Equal("true", winmd.GetMetadata("WinMDFile"));
Assert.Equal("Native", winmd.GetMetadata("WinMDFileType"));
Assert.False(string.IsNullOrEmpty(winmd.GetMetadata("Implementation")), "implementation should be set for native winmd");
- Assert.Equal(Path.GetFileNameWithoutExtension(winmd.ItemSpec) + ".dll", winmd.GetMetadata("Implementation"), StringComparer.OrdinalIgnoreCase);
+ Assert.Equal(Path.GetFileNameWithoutExtension(winmd.ItemSpec) + ".dll", winmd.GetMetadata("Implementation"), StringComparer.OrdinalIgnoreCase);
}
[Fact]
@@ -334,8 +449,8 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
targetMoniker: ".NETCore,Version=v5.0",
runtimeIdentifier: "win10-x86",
tryGetRuntimeVersion: tryGetRuntimeVersion);
-
- var winmd = result.CopyLocalItems.FirstOrDefault(c =>
+
+ var winmd = result.CopyLocalItems.FirstOrDefault(c =>
Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(winmd);
@@ -356,7 +471,7 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
runtimeIdentifier: "win10-x86",
tryGetRuntimeVersion: tryGetRuntimeVersion);
- var winmd = result.CopyLocalItems.FirstOrDefault(c =>
+ var winmd = result.CopyLocalItems.FirstOrDefault(c =>
Path.GetExtension(c.ItemSpec).Equals(".winmd", StringComparison.OrdinalIgnoreCase));
Assert.NotNull(winmd);
@@ -451,5 +566,81 @@ namespace Microsoft.NuGet.Build.Tasks.Tests
Assert.DoesNotContain("ClassLibrary1", result.ReferencedPackages.Select(t => t.ItemSpec));
}
+ private static LockFile GenerateLockFileWithoutTarget()
+ {
+ return new LockFile
+ {
+ Version = 2,
+ PackageSpec = new PackageSpec(new TargetFrameworkInformation[]
+ {
+ new TargetFrameworkInformation
+ {
+ FrameworkName = FrameworkConstants.CommonFrameworks.Net45,
+ Dependencies = new[]
+ {
+ new LibraryDependency
+ {
+ LibraryRange = new LibraryRange(
+ "System.Text",
+ new VersionRange(
+ minVersion: new NuGetVersion("4.5.0"),
+ originalString: "4.5.0"),
+ LibraryDependencyTarget.Package)
+ }
+ }
+ }
+ })
+ {
+ Version = new NuGetVersion("1.0.0"),
+ RestoreMetadata = new ProjectRestoreMetadata
+ {
+ ProjectUniqueName = @"X:\ProjectPath\ProjectPath.csproj",
+ ProjectName = "ProjectPath",
+ ProjectPath = @"X:\ProjectPath\ProjectPath.csproj",
+ OutputPath = @"X:\ProjectPath\obj\",
+ ProjectStyle = ProjectStyle.PackageReference,
+ OriginalTargetFrameworks = new string[] { "net45" },
+ TargetFrameworks = new List<ProjectRestoreMetadataFrameworkInfo>
+ {
+ new ProjectRestoreMetadataFrameworkInfo(NuGetFramework.Parse("net45"))
+ }
+ }
+ },
+ Libraries = new LockFileLibrary[]
+ {
+ new LockFileLibrary()
+ {
+ Name = "System.Text",
+ Version = NuGetVersion.Parse("4.5.0"),
+ Path = "system.text/4.5.0",
+ Type = LibraryType.Package
+ }
+ }
+ };
+ }
+
+ private static LockFile GenerateLockFileWithTarget()
+ {
+ var lockFile = GenerateLockFileWithoutTarget();
+
+ var target = new LockFileTarget()
+ {
+ TargetFramework = FrameworkConstants.CommonFrameworks.Net45
+ };
+
+ var targetLib = new LockFileTargetLibrary()
+ {
+ Name = "System.Text",
+ Version = new NuGetVersion("4.5.0"),
+ Type = LibraryType.Package
+ };
+
+ targetLib.Dependencies.Add(new PackageDependency("System", new VersionRange(NuGetVersion.Parse("4.5.0"))));
+ targetLib.CompileTimeAssemblies.Add(new LockFileItem("ref/net45/System.Text.dll"));
+ target.Libraries.Add(targetLib);
+ lockFile.Targets.Add(target);
+
+ return lockFile;
+ }
}
}
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/app.config b/src/Microsoft.NuGet.Build.Tasks.Tests/app.config
index 845f164..9def342 100644
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/app.config
+++ b/src/Microsoft.NuGet.Build.Tasks.Tests/app.config
@@ -1,6 +1,6 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="xunit.shadowCopy" value="false"/>
</appSettings>
-</configuration> \ No newline at end of file
+<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/></startup></configuration>
diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/project.json b/src/Microsoft.NuGet.Build.Tasks.Tests/project.json
deleted file mode 100644
index f31dee0..0000000
--- a/src/Microsoft.NuGet.Build.Tasks.Tests/project.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "dependencies": {
- "xunit": "2.1.0",
- "xunit.runner.visualstudio": "2.1.0"
- },
- "frameworks": { "net45": { } },
- "runtimes": { "win": { } }
-} \ No newline at end of file
diff --git a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs
index ac81c61..2f8bcda 100644
--- a/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs
+++ b/src/Microsoft.NuGet.Build.Tasks/ResolveNuGetPackageAssets.cs
@@ -1,16 +1,16 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
-using Microsoft.Build.Framework;
-using Microsoft.Build.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Security.Cryptography;
using System.Text;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
-using System.Security.Cryptography;
namespace Microsoft.NuGet.Build.Tasks
{
@@ -729,7 +729,7 @@ namespace Microsoft.NuGet.Build.Tasks
var runtimePiece = RuntimeIdentifier;
var runtimesSection = $"<{RuntimeIdentifiersProperty}>{RuntimeIdentifier}</{RuntimeIdentifiersProperty}>";
var missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierInCsproj);
- var missingRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifiersInCsproj);
+ var missingRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierPropertyInCsproj);
if (IsLockFileProjectJsonBased(ProjectLockFile))
{
@@ -739,13 +739,17 @@ namespace Microsoft.NuGet.Build.Tasks
missingRuntimesErrorString = nameof(Strings.MissingRuntimesSectionInProjectJson);
}
- bool hasRuntimesSection;
+ bool hasRuntimesSection = true;
try
{
- using (var streamReader = new StreamReader(ProjectLockFile.Replace(".lock.json", ".json")))
+ // try reading the project.json file only of the project is project.json based
+ if (IsLockFileProjectJsonBased(ProjectLockFile))
{
- var jsonFile = JObject.Load(new JsonTextReader(streamReader));
- hasRuntimesSection = jsonFile["runtimes"] != null;
+ using (var streamReader = new StreamReader(ProjectLockFile.Replace(".lock.json", ".json")))
+ {
+ var jsonFile = JObject.Load(new JsonTextReader(streamReader));
+ hasRuntimesSection = jsonFile["runtimes"] != null;
+ }
}
}
catch
@@ -766,8 +770,8 @@ namespace Microsoft.NuGet.Build.Tasks
private void GiveErrorForMissingFramework()
{
- var missingFrameworkErrorString = IsLockFileProjectJsonBased(ProjectLockFile) ?
- nameof(Strings.MissingFrameworkInProjectJson) :
+ var missingFrameworkErrorString = IsLockFileProjectJsonBased(ProjectLockFile) ?
+ nameof(Strings.MissingFrameworkInProjectJson) :
nameof(Strings.MissingFrameworkInCsproj);
ThrowExceptionIfNotAllowingFallback(missingFrameworkErrorString, TargetMonikers.First().ItemSpec);
diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs
index 6aebdb8..97b00ae 100644
--- a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs
+++ b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs
@@ -126,9 +126,9 @@ namespace Microsoft.NuGet.Build.Tasks {
/// <summary>
/// Looks up a localized string similar to Your project csproj file doesn&apos;t have the &quot;RuntimeIdentifiers&quot; property. You should add &apos;{0}&apos; to your project csproj file and then re-run NuGet restore..
/// </summary>
- internal static string MissingRuntimeIdentifiersInCsproj {
+ internal static string MissingRuntimeIdentifierPropertyInCsproj {
get {
- return ResourceManager.GetString("MissingRuntimeIdentifiersInCsproj", resourceCulture);
+ return ResourceManager.GetString("MissingRuntimeIdentifierPropertyInCsproj", resourceCulture);
}
}
diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.resx b/src/Microsoft.NuGet.Build.Tasks/Strings.resx
index 4e0906e..ea0945c 100644
--- a/src/Microsoft.NuGet.Build.Tasks/Strings.resx
+++ b/src/Microsoft.NuGet.Build.Tasks/Strings.resx
@@ -146,7 +146,7 @@
<value>Your project csproj file doesn't list '{0}' as a targeted runtime. You should add '{1}' to the "RuntimeIdentifiers" property in your project csproj file and then re-run NuGet restore.</value>
<comment>0 &amp;1 - Runtime Identifier</comment>
</data>
- <data name="MissingRuntimeIdentifiersInCsproj" xml:space="preserve">
+ <data name="MissingRuntimeIdentifierPropertyInCsproj" xml:space="preserve">
<value>Your project csproj file doesn't have the "RuntimeIdentifiers" property. You should add '{0}' to your project csproj file and then re-run NuGet restore.</value>
<comment>0 - Runtime Identifier</comment>
</data>