diff --git a/Tests/SonarScanner.MSBuild.Tasks.UnitTest/WriteProjectConfigFileTests.cs b/Tests/SonarScanner.MSBuild.Tasks.UnitTest/WriteProjectConfigFileTests.cs
index 07da66edd4..9e3eeea4c1 100644
--- a/Tests/SonarScanner.MSBuild.Tasks.UnitTest/WriteProjectConfigFileTests.cs
+++ b/Tests/SonarScanner.MSBuild.Tasks.UnitTest/WriteProjectConfigFileTests.cs
@@ -42,17 +42,22 @@ public void Execute_FileCreated()
FilesToAnalyzePath = @"c:\fullPath\files.txt",
OutPath = @"c:\fullPath\out\42\",
IsTest = false,
- TargetFramework = "target-42"
+ TargetFramework = "target-42",
+ ProjectAssetsFile = @"c:\fullPath\project.assets.json",
};
var reloadedConfig = ExecuteAndReloadConfig(task, testFolder);
- reloadedConfig.AnalysisConfigPath.Should().Be(@"c:\fullPath\config.xml");
- reloadedConfig.ProjectPath.Should().Be(@"c:\fullPath\project.xproj");
- reloadedConfig.OutPath.Should().Be(@"c:\fullPath\out\42\");
- reloadedConfig.FilesToAnalyzePath.Should().Be(@"c:\fullPath\files.txt");
- reloadedConfig.ProjectType.Should().Be(ProjectType.Product);
- reloadedConfig.TargetFramework.Should().Be("target-42");
+ reloadedConfig.Should().BeEquivalentTo(new ProjectConfig
+ {
+ AnalysisConfigPath = @"c:\fullPath\config.xml",
+ ProjectPath = @"c:\fullPath\project.xproj",
+ OutPath = @"c:\fullPath\out\42\",
+ FilesToAnalyzePath = @"c:\fullPath\files.txt",
+ ProjectType = ProjectType.Product,
+ TargetFramework = "target-42",
+ ProjectAssetsFile = @"c:\fullPath\project.assets.json",
+ });
}
[TestMethod]
@@ -68,7 +73,8 @@ public void Execute_AllPropertiesAreSet()
FilesToAnalyzePath = "not empty",
OutPath = "not empty",
IsTest = true,
- TargetFramework = "not empty"
+ TargetFramework = "not empty",
+ ProjectAssetsFile = "not empty",
};
var reloadedConfig = ExecuteAndReloadConfig(task, testFolder);
diff --git a/src/SonarScanner.MSBuild.Tasks/ProjectConfig.cs b/src/SonarScanner.MSBuild.Tasks/ProjectConfig.cs
index 844bd677ae..5fca7866d9 100644
--- a/src/SonarScanner.MSBuild.Tasks/ProjectConfig.cs
+++ b/src/SonarScanner.MSBuild.Tasks/ProjectConfig.cs
@@ -59,6 +59,12 @@ public class ProjectConfig
///
public string TargetFramework { get; set; }
+ ///
+ /// The location of the project.assets.json file produced by a NuGet restore.
+ /// This file location corresponds to the MSBuild property 'ProjectAssetsFile'.
+ ///
+ public string ProjectAssetsFile { get; set; }
+
///
/// Saves the project configuration to the specified file as XML.
///
diff --git a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets
index a56c1f6dec..3b5066f7c8 100644
--- a/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets
+++ b/src/SonarScanner.MSBuild.Tasks/Targets/SonarQube.Integration.targets
@@ -379,6 +379,9 @@
$(SonarProjectTelemetryFilePath)
+
+ $(ProjectAssetsFile)
+
@@ -617,7 +620,8 @@
FilesToAnalyzePath ="$(AnalysisFileList)"
OutPath="$(ProjectSpecificOutDir)"
IsTest="$(SonarQubeTestProject)"
- TargetFramework="$(TargetFramework)">
+ TargetFramework="$(TargetFramework)"
+ ProjectAssetsFile="$(ProjectAssetsFile)">
diff --git a/src/SonarScanner.MSBuild.Tasks/WriteProjectConfigFile.cs b/src/SonarScanner.MSBuild.Tasks/WriteProjectConfigFile.cs
index 9d8a581e34..222a060876 100644
--- a/src/SonarScanner.MSBuild.Tasks/WriteProjectConfigFile.cs
+++ b/src/SonarScanner.MSBuild.Tasks/WriteProjectConfigFile.cs
@@ -18,10 +18,8 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-using System.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
-using SonarScanner.MSBuild.Common;
namespace SonarScanner.MSBuild.Tasks;
@@ -54,6 +52,8 @@ public class WriteProjectConfigFile : Task
public string TargetFramework { get; set; }
+ public string ProjectAssetsFile { get; set; }
+
#endregion Input properties
[Output]
@@ -66,12 +66,13 @@ public override bool Execute()
ProjectConfigFilePath = Path.Combine(ConfigDir, FileConstants.ProjectConfigFileName);
var config = new ProjectConfig
{
- AnalysisConfigPath= AnalysisConfigPath,
- ProjectPath= ProjectPath,
- FilesToAnalyzePath= FilesToAnalyzePath,
- OutPath= OutPath,
+ AnalysisConfigPath = AnalysisConfigPath,
+ ProjectPath = ProjectPath,
+ FilesToAnalyzePath = FilesToAnalyzePath,
+ OutPath = OutPath,
ProjectType = IsTest ? ProjectType.Test : ProjectType.Product,
- TargetFramework = TargetFramework
+ TargetFramework = TargetFramework,
+ ProjectAssetsFile = ProjectAssetsFile,
};
config.Save(ProjectConfigFilePath);
return true;