0

Ok, so I currently have two projects.

Installer - .NET 4.0
Service - .NET 4.5.2

What I would like is for Installer to be built before the Service project, as the output files are bundled into the Installer output.

The problem i am facing is by default, the solution wants to build the Service project before the Installer.

If I go to Project Dependencies for the solution and add Service as a dependency of Installer. I can then build the solution fine from Visual Studio. However, my problem is when i try and build from the commandline which is a requirement for the build server. I get the following error.

C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Microsoft.Common.CurrentVersion.targets(1603,5): error : Project 'C:\Users\username\Source\Repos\agents\src\Service\LMS.Service.csproj' targets 'net452'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.0'. [C:\Users\username\Source\Repos\agents\src\Installer\Installer.csproj]

Which I am a bit confused by as I am not referencing the project directly, just adding it as a build dependency.

The command executed is dotnet build "C:/Users/username/Source/Repos/agents/src/LicenseMonitoringSystem.sln"

I have also tried the MSBuild equivalent of the command but still get the same error message.

Just for clarity, i am using the new .csproj format.

Update

MSBuild command

& "C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe" /m /v:normal /p:Configuration="Release" /p:Platform="Any CPU" /target:Build "C:/Users/username/Source/Repos/agents/src/LicenseMonitoringSystem.sln"

MSBuild output

"C:\Users\usernames\Source\Repos\agents\src\LicenseMonitoringSystem.sln" (Build target) (1) ->
       "C:\Users\username\Source\Repos\agents\src\Installer\Installer.csproj.metaproj" (default target) (8) ->
       "C:\Users\username\Source\Repos\agents\src\Installer\Installer.csproj" (default target) (9) ->
       (_GetProjectReferenceTargetFrameworkProperties target) ->
         C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1603,5): error : Project
        'C:\Users\username\Source\Repos\agents\src\Service\LMS.Service.csproj' targets 'net452'. It cannot be referenced by a project that targets '.NETFramew
       ork,Version=v4.0'. [C:\Users\username\Source\Repos\agents\src\Installer\Installer.csproj]
tjackadams
  • 815
  • 2
  • 9
  • 26
  • have you checked [build order](https://stackoverflow.com/a/5462857/4648586)? or specifically you have a good reason for the installer to be dependent of the service? – Bagus Tesa Apr 10 '18 at 11:49
  • @BagusTesa The build order does put Service before Installer, but this is not respected when executing from the cli. Installer shouldn't be dependent of Service just built after. The output of Service is bundled into an msi package when the Installer project is built. – tjackadams Apr 10 '18 at 11:58
  • 1
    Use dotnet.exe only for .NETCore projects. Projects that target the full framework should be built by MSBuild. – Hans Passant Apr 10 '18 at 12:02
  • @HansPassant MSBuild produces a nearly identical error message. Please see the update posted. – tjackadams Apr 10 '18 at 12:11

0 Answers0