AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

Build of solution fails #59

Closed mbabramo closed 5 years ago

mbabramo commented 6 years ago

A clone of the CodeGeneration.Roslyn solution failed to build. (I tried this both in Visual Studio 15.5.7 and the current preview of Visual Studio.) The Errors List shows the following error:

Severity Code Description Project File Line Suppression State Error MSB4062 The "GenerateCodeFromAttributes" task could not be loaded from the assembly C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src..\bin\CodeGeneration.Roslyn.Tests\Debug....\CodeGeneration.Roslyn.Tasks\Debug\net45\CodeGeneration.Roslyn.Tasks.dll. Could not load file or assembly 'file:///C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tasks\Debug\net45\CodeGeneration.Roslyn.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. CodeGeneration.Roslyn.Tests C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tasks\build\CodeGeneration.Roslyn.BuildTime.targets 20

Here is the full output of dotnet build:

PM> dotnet build Microsoft (R) Build Engine version 15.7.11.29948 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets(198,5): warning : A PackageReference for 'Microsoft.NETCore.App' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tool\CodeGeneration.Roslyn.Tool.csproj] Restore completed in 40.94 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tests.RunBuild\CodeGeneration.Roslyn.Tests.RunBuild.csproj. Restore completed in 43.8 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj. Restore completed in 45.25 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tests.Generators\CodeGeneration.Roslyn.Tests.Generators.csproj. Restore completed in 45.26 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tasks\CodeGeneration.Roslyn.Tasks.csproj. Restore completed in 3.01 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tests\CodeGeneration.Roslyn.Tests.csproj. Restore completed in 2.06 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn\CodeGeneration.Roslyn.csproj. Restore completed in 3.44 ms for C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tool\CodeGeneration.Roslyn.Tool.csproj. C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Microsoft.Common.CurrentVersion.targets(1126,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v2.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj] C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj : error MSB4057: The target "Build" does not exist in the project. C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj : error MSB4057: The target "Build" does not exist in the project. CodeGeneration.Roslyn.Attributes -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Attributes\Debug\net40\CodeGeneration.Roslyn.Attributes.dll CodeGeneration.Roslyn.Tasks -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tasks\Debug\net45\CodeGeneration.Roslyn.Tasks.dll CodeGeneration.Roslyn.Attributes -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Attributes\Debug\netstandard1.0\CodeGeneration.Roslyn.Attributes.dll CodeGeneration.Roslyn.Tasks -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tasks\Debug\netstandard1.5\CodeGeneration.Roslyn.Tasks.dll C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets(198,5): warning : A PackageReference for 'Microsoft.NETCore.App' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tool\CodeGeneration.Roslyn.Tool.csproj] CodeGeneration.Roslyn.Tests.RunBuild -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tests.RunBuild\Debug\net462\CodeGeneration.Roslyn.Tests.RunBuild.dll CodeGeneration.Roslyn -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn\Debug\netstandard1.5\CodeGeneration.Roslyn.dll CodeGeneration.Roslyn.Tests.Generators -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tests.Generators\Debug\netstandard1.5\CodeGeneration.Roslyn.Tests.Generators.dll CodeGeneration.Roslyn.Tool -> C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tool\Debug\netcoreapp1.0\dotnet-codegen.dll C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tasks\build\CodeGeneration.Roslyn.BuildTime.targets(20,5): error MSB6006: "dotnet" exited with code -2147450730. [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tests\CodeGeneration.Roslyn.Tests.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets(198,5): warning : A PackageReference for 'Microsoft.NETCore.App' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tool\CodeGeneration.Roslyn.Tool.csproj] C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets(198,5): warning : A PackageReference for 'Microsoft.NETCore.App' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tool\CodeGeneration.Roslyn.Tool.csproj] C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Microsoft.Common.CurrentVersion.targets(1126,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v2.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj] C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj : error MSB4057: The target "Build" does not exist in the project. C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj : error MSB4057: The target "Build" does not exist in the project. C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tasks\build\CodeGeneration.Roslyn.BuildTime.targets(20,5): error MSB6006: "dotnet" exited with code -2147450730. [C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\src\CodeGeneration.Roslyn.Tests\CodeGeneration.Roslyn.Tests.csproj] 2 Warning(s) 4 Error(s)

mbabramo commented 6 years ago

I also tried running against sdk 2.1.4, and I received a similar error. I decided to try to go back to 1.1.8, but then sensibly received the error, "The version of Microsoft.NET.Sdk used by this project is insufficient to support references to libraries targeting .NET Standard 1.5 or higher. Please install version 2.0 or higher of the .NET Core SDK."

Finally, I thought I found the sweetspot with sdk 2.0.2. This at least discovers the project tests and avoids the errors above. But then I received another error: "The process cannot access the file 'C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tasks\Debug\net45\CodeGeneration.Roslyn.Tasks.dll' because it is being used by another process."

amis92 commented 6 years ago

@mbabramo The first error:

C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\Microsoft.Common.CurrentVersion.targets(1126,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v2.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

is expected if you didn't have .NET Framework 2.0 SDK installed - the CodeGeneration.Roslyn.Attributes project has net20 target among multiple others, and so to build it you need corresponding SDK.

The second error:

"The process cannot access the file 'C:\Users\mbabr\source\repos\CodeGeneration.Roslyn\bin\CodeGeneration.Roslyn.Tasks\Debug\net45\CodeGeneration.Roslyn.Tasks.dll' because it is being used by another process."

is actually a common problem that I don't know how to permanently resolve (@AArnott ?), but a typical workaround is to kill all MSBuild.exe processes:

image

For some reason one MSBuild instance locks said dll and other instances can't access it.

amis92 commented 5 years ago

Closing as deprecated. Project went through major refactor, documentation was updated.