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/Json/Json.Designer.cs b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs index e75ea94..9137dec 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.Designer.cs @@ -358,5 +358,25 @@ namespace Microsoft.NuGet.Build.Tasks.Tests.Json { return ResourceManager.GetString("Win10_xunit", resourceCulture); } } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] WithoutTargets_assets { + get { + object obj = ResourceManager.GetObject("WithoutTargets_assets", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] WithTargets_assets { + get { + object obj = ResourceManager.GetObject("WithTargets_assets", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx index 993a1fe..0286e1b 100644 --- a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/Json.resx @@ -151,4 +151,10 @@ multipleprojectfiledependencygroups_casemismatch.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 + + WithoutTargets.assets.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + WithTargets.assets.json;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json new file mode 100644 index 0000000..bef673f --- /dev/null +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithTargets.assets.json @@ -0,0 +1,51 @@ +{ + "version": 2, + "targets": { + ".NETFramework,Version=v4.5": { + "System.Text/4.5.0": { + "type": "package", + "dependencies": { + "System": "4.5.0" + }, + "compile": { + "ref/net45/System.Text.dll": {} + } + } + } + }, + "libraries": { + "System.Text/4.5.0": { + "type": "package", + "path": "system.text/4.5.0" + } + }, + "projectFileDependencyGroups": {}, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "X:\\ProjectPath\\ProjectPath.csproj", + "projectName": "ProjectPath", + "projectPath": "X:\\ProjectPath\\ProjectPath.csproj", + "outputPath": "X:\\ProjectPath\\obj\\", + "projectStyle": "PackageReference", + "originalTargetFrameworks": [ + "net45" + ], + "frameworks": { + "net45": { + "projectReferences": {} + } + } + }, + "frameworks": { + "net45": { + "dependencies": { + "System.Text": { + "target": "Package", + "version": "[4.5.0, )" + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json new file mode 100644 index 0000000..4eae5df --- /dev/null +++ b/src/Microsoft.NuGet.Build.Tasks.Tests/Json/WithoutTargets.assets.json @@ -0,0 +1,39 @@ +{ + "version": 2, + "targets": {}, + "libraries": { + "System.Text/4.5.0": { + "type": "package", + "path": "system.text/4.5.0" + } + }, + "projectFileDependencyGroups": {}, + "project": { + "version": "1.0.0", + "restore": { + "projectUniqueName": "X:\\ProjectPath\\ProjectPath.csproj", + "projectName": "ProjectPath", + "projectPath": "X:\\ProjectPath\\ProjectPath.csproj", + "outputPath": "X:\\ProjectPath\\obj\\", + "projectStyle": "PackageReference", + "originalTargetFrameworks": [ + "net45" + ], + "frameworks": { + "net45": { + "projectReferences": {} + } + } + }, + "frameworks": { + "net45": { + "dependencies": { + "System.Text": { + "target": "Package", + "version": "[4.5.0, )" + } + } + } + } + } +} \ No newline at end of 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..83774b4 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 @@ Properties Microsoft.NuGet.Build.Tasks.Tests Microsoft.NuGet.Build.Tasks.Tests - v4.5 + v4.6.2 512 true @@ -72,7 +72,9 @@ - + + Designer + @@ -83,8 +85,9 @@ - + + @@ -92,6 +95,7 @@ ResXFileCodeGenerator Json.Designer.cs + Designer ResXFileCodeGenerator @@ -101,6 +105,16 @@ + + + 2.3.1 + + + 2.3.1 + runtime; build; native; contentfiles; analyzers + all + + + + + <_HandlePackageFileConflictsAfter>$(_HandlePackageFileConflictsAfter);ResolveNuGetPackageAssetsNonAOT + + + - - + + + + + + - - %(NonAheadOfTimeRuntimeImplementations.FullPath) - %(NonAheadOfTimeRuntimeImplementations.FullPath) + + + + + <_ReferencesFromNuGetPackages Remove="%(ReferencePath.FileName)" Condition="'%(ReferencePath.ResolvedFrom)' == 'ImplicitlyExpandTargetFramework'" /> + + + + <_ResolvedProjectReferencePaths Include="@(_ReferencesFromNuGetPackages)" Condition="'%(_ReferencesFromNuGetPackages.NuGetSourceType)' == 'Project'" /> + + + + + + + + true + + + + + + + + + + + + + %(ReferenceCopyLocalPaths.FullPath) + %(ReferenceCopyLocalPaths.FullPath) @@ -264,7 +329,7 @@ Copyright (c) .NET Foundation. All rights reserved. --> .NETCore,Version=v5.0 - UAP,Version=v10.0.15138 + UAP,Version=v10.0.15138 .NETCore,Version=v5.0 <_ComputeNetCoreFrameworkInjectionParametersBeforeTargets Condition="'$(AppxPackage)' == 'true' and '$(TargetPlatformIdentifier)' == 'UAP'">BeforeGenerateProjectPriFile @@ -298,14 +363,14 @@ Copyright (c) .NET Foundation. All rights reserved. @(_NuGetInjectionSourceDirectories->'%(Identity)\RS2.project.lock.json') - @(_NuGetInjectionSourceDirectories->'%(Identity)\RS3.project.lock.json') + @(_NuGetInjectionSourceDirectories->'%(Identity)\RS3.project.lock.json') @(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json') .NETCore,Version=v5.0 @(_NuGetInjectionSourceDirectories->'%(Identity)\project.lock.json') - $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'NETCoreSDK', null, RegistryView.Registry32, RegistryView.Default)) + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\NuGet\Repository', 'UWPNugetPackages', null, RegistryView.Registry32, RegistryView.Default)) _analyzers = new List(); private readonly List _copyLocalItems = new List(); private readonly List _references = new List(); @@ -215,7 +217,11 @@ namespace Microsoft.NuGet.Build.Tasks { if (!_fileExists(ProjectLockFile)) { - throw new ExceptionFromResource(nameof(Strings.LockFileNotFound), ProjectLockFile); + var errorMessage = IsLockFileProjectJsonBased(ProjectLockFile) ? + nameof(Strings.LockFileNotFoundForProjectJson) : + nameof(Strings.LockFileNotFoundForProjectFile); + + throw new ExceptionFromResource(errorMessage, ProjectLockFile); } JObject lockFile; @@ -688,7 +694,7 @@ namespace Microsoft.NuGet.Build.Tasks } else { - ThrowExceptionIfNotAllowingFallback(nameof(Strings.MissingFramework), TargetMonikers.First().ItemSpec); + GiveErrorForMissingFramework(); } // If we're still here, that means we're allowing fallback, so let's try @@ -707,23 +713,47 @@ namespace Microsoft.NuGet.Build.Tasks var firstTarget = (JObject)enumerableTargets.FirstOrDefault().Value; if (firstTarget == null) { - throw new ExceptionFromResource(nameof(Strings.NoTargetsInLockFile)); + GiveErrorForNoTargets(); } return firstTarget; } + private void GiveErrorForNoTargets() + { + var noTargetsInLockFileErrorString = IsLockFileProjectJsonBased(ProjectLockFile) ? + nameof(Strings.NoTargetsInLockFileForProjectJson) : + nameof(Strings.NoTargetsInLockFileForProjectFile); + + throw new ExceptionFromResource(noTargetsInLockFileErrorString); + } + private void GiveErrorForMissingRuntimeIdentifier() { - string runtimePiece = '"' + RuntimeIdentifier + "\": { }"; + var runtimePiece = RuntimeIdentifier; + var runtimesSection = $"<{RuntimeIdentifiersProperty}>{RuntimeIdentifier}"; + var missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierInProjectFile); + var missingRuntimesErrorString = nameof(Strings.MissingRuntimeIdentifierPropertyInProjectFile); - bool hasRuntimesSection; + if (IsLockFileProjectJsonBased(ProjectLockFile)) + { + runtimePiece = '"' + RuntimeIdentifier + "\": { }"; + runtimesSection = "\"runtimes\": { " + runtimePiece + " }"; + missingRuntimeInRuntimesErrorString = nameof(Strings.MissingRuntimeInProjectJson); + missingRuntimesErrorString = nameof(Strings.MissingRuntimesSectionInProjectJson); + } + + 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 @@ -734,15 +764,23 @@ namespace Microsoft.NuGet.Build.Tasks if (hasRuntimesSection) { - ThrowExceptionIfNotAllowingFallback(nameof(Strings.MissingRuntimeInRuntimesSection), RuntimeIdentifier, runtimePiece); + ThrowExceptionIfNotAllowingFallback(missingRuntimeInRuntimesErrorString, RuntimeIdentifier, runtimePiece); } else { - var runtimesSection = "\"runtimes\": { " + runtimePiece + " }"; - ThrowExceptionIfNotAllowingFallback(nameof(Strings.MissingRuntimesSection), runtimesSection); + ThrowExceptionIfNotAllowingFallback(missingRuntimesErrorString, runtimesSection); } } + private void GiveErrorForMissingFramework() + { + var missingFrameworkErrorString = IsLockFileProjectJsonBased(ProjectLockFile) ? + nameof(Strings.MissingFrameworkInProjectJson) : + nameof(Strings.MissingFrameworkInProjectFile); + + ThrowExceptionIfNotAllowingFallback(missingFrameworkErrorString, TargetMonikers.First().ItemSpec); + } + private void ThrowExceptionIfNotAllowingFallback(string resourceName, params string[] messageArgs) { if (!AllowFallbackOnTargetSelection) @@ -968,7 +1006,11 @@ namespace Microsoft.NuGet.Build.Tasks if (libraryObject == null) { - throw new ExceptionFromResource(nameof(Strings.MissingPackageInTargetsSection), package.Key); + var errorMessage = IsLockFileProjectJsonBased(ProjectLockFile) ? + nameof(Strings.MissingPackageInTargetsForProjectJson) : + nameof(Strings.MissingPackageInTargetsSectionForProjectFile); + + throw new ExceptionFromResource(errorMessage, package.Key); } // If this is a project then we need to figure out it's relative output path @@ -1042,5 +1084,10 @@ namespace Microsoft.NuGet.Build.Tasks return String.Empty; } } + + private static bool IsLockFileProjectJsonBased(string lockFilePath) + { + return lockFilePath.EndsWith("lock.json", StringComparison.OrdinalIgnoreCase); + } } } diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs index 9b3de63..0056db5 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs +++ b/src/Microsoft.NuGet.Build.Tasks/Strings.Designer.cs @@ -19,7 +19,7 @@ namespace Microsoft.NuGet.Build.Tasks { // 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 Strings { @@ -69,75 +69,111 @@ namespace Microsoft.NuGet.Build.Tasks { } } + /// + /// Looks up a localized string similar to Assets file {0} couldn't be found. Run a NuGet package restore to generate this file.. + /// + internal static string LockFileNotFoundForProjectFile { + get { + return ResourceManager.GetString("LockFileNotFoundForProjectFile", resourceCulture); + } + } + /// /// Looks up a localized string similar to Lock file {0} couldn't be found. Run a NuGet package restore to generate this file.. /// - internal static string LockFileNotFound { + internal static string LockFileNotFoundForProjectJson { get { - return ResourceManager.GetString("LockFileNotFound", resourceCulture); + return ResourceManager.GetString("LockFileNotFoundForProjectJson", resourceCulture); } } /// - /// Looks up a localized string similar to Your project is not referencing the "{0}" framework. Add a reference to "{0}" in the "frameworks" section of your project.json, and then re-run NuGet restore.. + /// Looks up a localized string similar to Your project does not reference "{0}" framework. Add a reference to "{0}" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.. /// - internal static string MissingFramework { + internal static string MissingFrameworkInProjectFile { get { - return ResourceManager.GetString("MissingFramework", resourceCulture); + return ResourceManager.GetString("MissingFrameworkInProjectFile", resourceCulture); } } /// - /// Looks up a localized string similar to Your project is consuming assets from the project '{0}' but no MSBuild project is found in the project.lock.json. Check the project references in your project file, and re-run NuGet restore.. + /// Looks up a localized string similar to Your project does not reference "{0}" framework. Add a reference to "{0}" in the "frameworks" section of your project.json and then re-run NuGet restore.. /// - internal static string MissingMSBuildPathInProjectPackage { + internal static string MissingFrameworkInProjectJson { get { - return ResourceManager.GetString("MissingMSBuildPathInProjectPackage", resourceCulture); + return ResourceManager.GetString("MissingFrameworkInProjectJson", resourceCulture); } } /// /// Looks up a localized string similar to The package '{0}' could not be found in the libraries section of the lock file. This may indicate your lock file is corrupted.. /// - internal static string MissingPackageInTargetsSection { + internal static string MissingPackageInTargetsForProjectJson { get { - return ResourceManager.GetString("MissingPackageInTargetsSection", resourceCulture); + return ResourceManager.GetString("MissingPackageInTargetsForProjectJson", resourceCulture); } } /// - /// Looks up a localized string similar to The project.json is referencing the project '{0}', but an output path was not specified on an item in the {1} property.. + /// Looks up a localized string similar to The package '{0}' could not be found in the libraries section of the assets file. This may indicate your assets file is corrupted.. /// - internal static string MissingProjectReference { + internal static string MissingPackageInTargetsSectionForProjectFile { get { - return ResourceManager.GetString("MissingProjectReference", resourceCulture); + return ResourceManager.GetString("MissingPackageInTargetsSectionForProjectFile", resourceCulture); } } /// - /// Looks up a localized string similar to Your project.json doesn't list '{0}' as a targeted runtime. You should add '{1}' inside your "runtimes" section in your project.json, and then re-run NuGet restore.. + /// Looks up a localized string similar to Your project file doesn't list '{0}' as a "RuntimeIdentifier". You should add '{1}' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.. /// - internal static string MissingRuntimeInRuntimesSection { + internal static string MissingRuntimeIdentifierInProjectFile { get { - return ResourceManager.GetString("MissingRuntimeInRuntimesSection", resourceCulture); + return ResourceManager.GetString("MissingRuntimeIdentifierInProjectFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Your project file doesn't have the "RuntimeIdentifiers" property. You should add '{0}' to your project file and then re-run NuGet restore.. + /// + internal static string MissingRuntimeIdentifierPropertyInProjectFile { + get { + return ResourceManager.GetString("MissingRuntimeIdentifierPropertyInProjectFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Your project.json doesn't list '{0}' as a "RuntimeIdentifier". You should add '{1}' inside your "runtimes" section in your project.json and then re-run NuGet restore.. + /// + internal static string MissingRuntimeInProjectJson { + get { + return ResourceManager.GetString("MissingRuntimeInProjectJson", resourceCulture); } } /// /// Looks up a localized string similar to Your project.json doesn't have a runtimes section. You should add '{0}' to your project.json and then re-run NuGet restore.. /// - internal static string MissingRuntimesSection { + internal static string MissingRuntimesSectionInProjectJson { get { - return ResourceManager.GetString("MissingRuntimesSection", resourceCulture); + return ResourceManager.GetString("MissingRuntimesSectionInProjectJson", resourceCulture); } } /// - /// Looks up a localized string similar to No targets could be found in the lock file. Make sure you have a supports or runtimes section i your project.json file.. + /// Looks up a localized string similar to No targets could be found in the assets file. Make sure you have "RuntimeIdentifiers" property in your project file.. /// - internal static string NoTargetsInLockFile { + internal static string NoTargetsInLockFileForProjectFile { get { - return ResourceManager.GetString("NoTargetsInLockFile", resourceCulture); + return ResourceManager.GetString("NoTargetsInLockFileForProjectFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to No targets could be found in the lock file. Make sure you have a supports or runtimes section in your project.json file.. + /// + internal static string NoTargetsInLockFileForProjectJson { + get { + return ResourceManager.GetString("NoTargetsInLockFileForProjectJson", resourceCulture); } } diff --git a/src/Microsoft.NuGet.Build.Tasks/Strings.resx b/src/Microsoft.NuGet.Build.Tasks/Strings.resx index 16d5d64..0e26628 100644 --- a/src/Microsoft.NuGet.Build.Tasks/Strings.resx +++ b/src/Microsoft.NuGet.Build.Tasks/Strings.resx @@ -119,38 +119,67 @@ The preprocessor token '{0}' has been given more than one value. Choosing '{1}' as the value. + 0 token +1 - chosen value - + + Assets file {0} couldn't be found. Run a NuGet package restore to generate this file. + 0 - assets file path + + Lock file {0} couldn't be found. Run a NuGet package restore to generate this file. + 0 - lock file path - - Your project is not referencing the "{0}" framework. Add a reference to "{0}" in the "frameworks" section of your project.json, and then re-run NuGet restore. + + Your project does not reference "{0}" framework. Add a reference to "{0}" in the "TargetFrameworks" property of your project file and then re-run NuGet restore. + 0 - target framework - - Your project is consuming assets from the project '{0}' but no MSBuild project is found in the project.lock.json. Check the project references in your project file, and re-run NuGet restore. + + Your project does not reference "{0}" framework. Add a reference to "{0}" in the "frameworks" section of your project.json and then re-run NuGet restore. + 0 - target framework - + The package '{0}' could not be found in the libraries section of the lock file. This may indicate your lock file is corrupted. + 0 package id - - The project.json is referencing the project '{0}', but an output path was not specified on an item in the {1} property. + + The package '{0}' could not be found in the libraries section of the assets file. This may indicate your assets file is corrupted. + 0 package id - - Your project.json doesn't list '{0}' as a targeted runtime. You should add '{1}' inside your "runtimes" section in your project.json, and then re-run NuGet restore. + + Your project file doesn't list '{0}' as a "RuntimeIdentifier". You should add '{1}' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore. + 0 &1 - Runtime Identifier - + + Your project file doesn't have the "RuntimeIdentifiers" property. You should add '{0}' to your project file and then re-run NuGet restore. + 0 - Runtime Identifier + + + Your project.json doesn't list '{0}' as a "RuntimeIdentifier". You should add '{1}' inside your "runtimes" section in your project.json and then re-run NuGet restore. + 0 - Runtime Identifier + + Your project.json doesn't have a runtimes section. You should add '{0}' to your project.json and then re-run NuGet restore. + 0 - Runtime Identifier - - No targets could be found in the lock file. Make sure you have a supports or runtimes section i your project.json file. + + No targets could be found in the assets file. Make sure you have "RuntimeIdentifiers" property in your project file. + + + No targets could be found in the lock file. Make sure you have a supports or runtimes section in your project.json file. The package {0} with version {1} could not be found in {2}. Run a NuGet package restore to download the package. + 0 - package id +1 - package version +2 - package folder path The {0} property must be set in order to consume preprocessed content. + 0 - directory path The token '{0}' is unrecognized. + 0 - token \ No newline at end of file