Building Reporting Service .RPTProj files in Visual Studio 2022 from the command line

The Issue

We have a number of projects that use the old style SQL Server Reporting Services (SSRS) .RPTProj project format. These projects are not supported in Visual Studio 2022 out of the box, but there is an extension in the Marketplace that adds the functionality back so you can build them in the IDE.

However, we want to build our RDL files as part of our CI process, and this is where we hit a problem. When we attempt a build with MSBuild it fails with an error about missing .NET 4.0 SDK/Targeting Pack.

"C:\projects\src\Reports.sln" (default target) (1) ->
"C:\projects\src\Reporting\Reporting.rptproj" (default target) (2) ->
(GetReferenceAssemblyPaths target) ->
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(12
29,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.0 were not found. To resolve this, install th
e Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Fram
ework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\projects\src\Reporting\Reporting.rptproj]

    0 Warning(s)
    1 Error(s)

Interestingly, if we try to build from the command line on a developer PC we get the same error, so it is not that the reporting service VS extension is not installed on the build agent, it is that the required MSBuild targets are not installed.

The Solution

You would assume the solution would be to install the missing SDK/Targeting Pack on the agent. However, there is no C# compilation in our .RPTProj files, so why do we even need the SDK/Targeting Pack?

The fix was to just update the .RPTProj file with a TargetFrameworkVersion>v4.8</TargetFrameworkVersion> block for each <PropertyGroup Condition= .... i.e. to tell MSBuild to use the .NET version installed.

  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
    <FullPath>Release</FullPath>
    <OutputPath>bin\Release</OutputPath>
    <ErrorLevel>2</ErrorLevel>
    <OverwriteDatasets>False</OverwriteDatasets>
    <OverwriteDataSources>False</OverwriteDataSources>
    <TargetServerVersion>SSRS2008R2</TargetServerVersion>
    <Platform>Win32</Platform>
    <TargetReportFolder>Reporting</TargetReportFolder>
    <TargetDatasetFolder>Datasets</TargetDatasetFolder>
    <TargetDatasourceFolder>Data Sources</TargetDatasourceFolder>
    <TargetReportPartFolder>Report Parts</TargetReportPartFolder>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
  </PropertyGroup>

Once this was done the command line build worked fine on both a developers PC and Microsoft hosted build agent. So, avoiding the need to install an out of support version of .NET.

For the original version of this post see Richard Fennell's personal blog at Building Reporting Service .RPTProj files in Visual Studio 2022 from the command line