I'm building a solution that contains a class library, a UnitTest Project and a .vdproj setup project. Because MSBuild cannot handle vdproj I'm using devenv.com. I'm calling C:\NuGet\nuget.exe restore "%WORKSPACE%\solution.sln" -ConfigFile C:\NuGet\NuGet.config before the build starts and build with "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com" rotring.tacton.export.sln /build "ci".
After that I execute the tests with "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "%WORKSPACE%\testproject.test\bin\ci\tests.dll".
The nuget restore command tells me that every package has been restored correctly and to the right place:
Added package 'package.1.9.11' to folder 'C:\dev\workspace\solution\packages'.
But still I'm getting the error:
error CS0234: The type or namespace name 'sometype' does not exist in the namespace 'somenamespace' (are you missing an assembly reference?)
Local builds just work fine even when I'm executing the console build mentioned above manually.
Do I need to restore the packages somehow with devenv.com? Isn't the advantage of PackageReference that all packages are stored at the same place compared to packages.config?
Update: I managed to find a partly myself. One thing was that my Test-Project was not migrated to PackageReference and caused an error.
However I was able to build the solution by first restoring the packages with MSBuild:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" /t:Restore /p:RestoreConfigFile="C:\NuGet\NuGet.config"
And then building the solution with devenv.com:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com" solution.sln /build "ci"
Now the only problem I face is that msbuild only restores the packages from the main project and doesn't care about the Test-Project.
Related
I am trying to set up a new TeamCity build job and am facing a build issue.
The build failed because of missing references within ResolveProjectReferences step.
For instance :
JSonTools\JSonHelper.cs(21, 7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Prior to the build step, 2 restore nuget steps are set up and both ran successfully (one for sdk like project and the second for previous version, in this order)
When I run my solution on the agent and restore nuget packages through VS it is working fine (and TC job will run successfully if made on the same agent)
I noticed the dlls pulled during the restore nuget steps are in the path of my sln, while it seems to be require on others path.
Several VCS are set for this job and from what i can see/understand, the failing projects seem to require the dll to be in their own path under the packages folder.
\this
\is
\my
\path
Project1.csproj
packages\ (<- contains all the Dlls)
\folder1
\Project2.csproj
\Project3.csproj
\packages\ (I have the feeling some Dlls should be here but the folder doesn't exist)
\folder2
\Project4.csproj
\packages\ (same as previously)
Did I missed something ?
Any help would be appreciated.
Thanks,
Cervelle
I am working on an Azure Functions project which targets .NET Standard 2.0.
It builds successfully, but when I run it locally, the following error occurs:
Could not load file or assembly 'Microsoft.Extensions.Options, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
I understand that it cannot find the above DLL.
What is confusing to me is that Nuget Package manager indicates that it IS installed.
I am using Process Monitor to verify where the build engine is probing for this dll.
Here is where it probes for Microsoft.Extensions.Options.dll
C:\dir1\Solution\ProjectName\bin\Debug\netstandard2.0\Microsoft.Extensions.Options.dll
C:\dir1\Solution\ProjectName\bin\Debug\netstandard2.0\bin\Microsoft.Extensions.Options.dll
The above is confusing me because, it IS installed here:
C:\dir1\Solution\ProjectName\bin\Debug\netstandard2.0
I can see it using the File Explorer. The precise version is 5.0.20.51904 (right-click the dll, Details tab, File version field).
However, it does NOT appear in
C:\dir1\Solution\ProjectName\bin\Debug\netstandard2.0\bin\
No matter how many times I clean and rebuild, or manually delete the above bin folders, Microsoft.Extensions.Options is never generated in
C:\dir1\Solution\ProjectName\bin\Debug\netstandard2.0\bin
At this point, I'm confused and not sure what to do next, because the binding engine is telling me that it cannot find something, which is indeed where it is looking. How can I solve this problem? How can I get the binding engine to use the dll which I have explicitly installed?
It also probes these folders as well:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.1\Facades\Microsoft.Extensions.Options.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\Microsoft.Extensions.Options.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\Microsoft.Extensions.Options.dll
C:\Program Files\IIS\Microsoft Web Deploy V3\Microsoft.Extensions.Options.dll
Extra info:
Azure Functions Core Tools
Core Tools Version: 3.0.3284 Commit hash:
98bc25e668274edd175a1647fe5a9bc4ffb6887d
Function Runtime Version: 3.0.15371.0
I have .Net Core 3.1 console application which is referring to a class library project FxCore which is added as a reference.
class library csproj has <TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472</TargetFrameworks> I have tried changing it to <TargetFrameworks>net45;</TargetFrameworks>, but still getting the same error.
I am getting the below error., I have tried clean -> ReBuild, Reopen the visual studio 2019 (version 16.5.2)
1>------ Build started: Project: FxCore, Configuration: Debug Any CPU
------ 1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011: "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props"
cannot be imported again. It was already imported at "C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)".
This is most likely a build authoring error. This subsequent import
will be ignored. 1>C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3):
warning MSB4011: "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets"
cannot be imported again. It was already imported at
"J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a
build authoring error. This subsequent import will be ignored.
1>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2081,5):
warning MSB3245: Could not resolve this reference. Could not locate
the assembly "FXEntity, Version=1.0.1.12, Culture=neutral,
processorArchitecture=MSIL". Check to make sure the assembly exists on
disk. If this reference is required by your code, you may get
compilation errors. 1>FxCore ->
J:\Test\core\fx-core\bin\Debug\FxCore.dll
1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011:
"C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props"
cannot be imported again. It was already imported at "C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)".
This is most likely a build authoring error. This subsequent import
will be ignored. 1>C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3):
warning MSB4011: "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets"
cannot be imported again. It was already imported at
"J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a
build authoring error. This subsequent import will be ignored.
1>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011:
"C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props"
cannot be imported again. It was already imported at "C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)".
This is most likely a build authoring error. This subsequent import
will be ignored. 1>C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3):
warning MSB4011: "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets"
cannot be imported again. It was already imported at
"J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a
build authoring error. This subsequent import will be ignored.
1>J:\Test\core\fx-core\FxCore.csproj : warning NU1603: FxCore depends
on Microsoft.Practices.ServiceLocation (>= 1.3.0) but
Microsoft.Practices.ServiceLocation 1.3.0 was not found. An
approximate best match of Microsoft.Practices.ServiceLocation 1.4.11
was resolved. 1>Done building project "FxCore.csproj". 1>Done building
project "FxCore.csproj". 2>------ Build started: Project:
CoreConsoleApp, Configuration: Debug Any CPU ------
2>J:\Test\core\fx-core\FxCore.csproj(3,3): warning MSB4011:
"C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Microsoft.Common.props"
cannot be imported again. It was already imported at "C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props (40,3)".
This is most likely a build authoring error. This subsequent import
will be ignored. 2>C:\Program
Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets(37,3):
warning MSB4011: "C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.CSharp.targets"
cannot be imported again. It was already imported at
"J:\Test\core\fx-core\FxCore.csproj (120,3)". This is most likely a
build authoring error. This subsequent import will be ignored.
2>C:\Program Files (x86)\Microsoft Visual
Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1655,5):
warning NU1702: ProjectReference 'J:\Test\core\fx-core\FxCore.csproj'
was resolved using '.NETFramework,Version=v4.6.1' instead of the
project target framework '.NETCoreApp,Version=v3.1'. This project may
not be fully compatible with your project.
2>J:\Test\core\CoreConsoleApp\Program.cs(2,7,2,9): error CS0246: The
type or namespace name 'FX' could not be found (are you missing a
using directive or an assembly reference?)
2>J:\Test\core\CoreConsoleApp\Program.cs(7,24,7,32): error CS0246: The
type or namespace name 'FxCommon' could not be found (are you missing
a using directive or an assembly reference?) 2>Done building project
"CoreConsoleApp.csproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
But in the Program.cs I am able to use the code, IntelliSense not showing any error.
using System;
using FX.Core;
namespace CoreConsoleApp
{
class Program
{
private static FxCommon _fxCommon = new FxCommon();
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
_fxCommon.Logger.LogWrite("hello");
}
}
}
I am not able to run the console application due to this, please help.
.NET Core doesn't consume .NET Framework (net###) targets; it can consume netstandard* and netcoreapp*.
So; your FxCore is going to need to target/multi-target one of .NET Standard or .NET Core.
In terms of choice of what to target/multi-target:
target netstandard* - if you don't need anything framework-specific in the implementation
multi-target netcoreapp* and netstandard* - if you want to use netcoreapp* features when they are available, or use a down-level common implementation otherwise
multi-target netcoreapp* and net### - if the implementations are completely platform specific and no common implementation is possible
(where * / ### is your choice of versions - probably netstandard2.1, netcoreapp3.1 and net472/net48 at the current time)
I have solved the issue by removing the below lines from the class library csproj file.
<PropertyGroup>
<TargetFrameworks>net45;net451;net452;net46;net461;net462;net47;net471;net472</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
I have AspNet.MVC application and want to build MVC views during the build (only in Release configuration).
I create this target
<Target Name="BuildViews" Condition="'$(configuration)'=='Release'" AfterTargets="Build">
<AspNetCompiler VirtualPath="/" PhysicalPath="$(ProjectDir)" />
</Target>
In Debug configuration it builds
In Release it fails with error
error MSB4062: The "Microsoft.Build.Tasks.AspNetCompiler" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the <UsingTask> 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.
Installing Microsoft.Build.Tasks.Core, adding UsingTask and other manipulations doesnt help(
Maybe anyone knows the solution?
Target framework - new 4.8
C# version - 8
IDE - JetBrains Rider 2019.3.1
MSBuild Path - C:\Program Files\dotnet\sdk\3.1.101\MSBuild.dll
Project format - Microsoft.NET.Sdk (.net core format)
Also, i try to change MSBuild Path (in rider settings)
If i change it to exe-file in rider folder C:\Program Files\JetBrains\JetBrains Rider 2019.3.1\tools\MSBuild\Current\Bin\MSBuild.exe, it works
But this is not a solution, because it doesnt work on TeamCity agents, where rider is not installed
Just had the same issue with the BuildTools in Team City... Depending on what build tools you need there are different paths to it as some exist in \Microsoft Visual Studio\2019\Professional\MSBuild\ and some are in MSBuild\2019\<path>. For me this issue was resolved by updating my .config towards VS and not the build tools.
I am working on setting a project to use bamboo for CI testing, but have hit a hitch when attempting to compile unit tests. We are using the .NET framework 4.5 and NUnit v2.6.3.13283. When I am in bamboo, I have set up the specific job to check out the source code when a new commit is pushed, and then use MSBuild to build the code. Unfortunately, when it reaches this second step, it decides that it no longer understands what NUnit is.
I have the nunit.framework.dll in the same directory (bin\Debug) as the class .dll, so I'm definitely confused as to how I should go about having MSBuild work out building the NUnit tests.
Any help would be appreciated.
EDIT: Error log for those not faint of heart.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt
/warn:4 /define:DEBUG;TRACE
/reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll
/reference:"C:\build-dir\UCL-UNL-JOB1\Unit Class
Library\bin\Debug\Unit Class Library.dll" /debug+ /debug:full
/filealign:512 /optimize-
/out:obj\Debug\UnitClassLibraryNUnitTests.dll /target:library
AngleNUnitTests.cs
"C:\Users\Bamboo\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"
AngleNUnitTests.cs(5,7): error CS0246: The type or namespace name
'NUnit' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
AngleNUnitTests.cs(12,10): error CS0246: The type or namespace name
'Test' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
etc.
You need to use a previous task to MSBuild one (Maybe you could consider to use the VisualStudio Task it works like a charm).
This previous task is a Command Task, it will update the Dlls related to the NuGet Package, in order to achieve it:
Create a New Executable on Bamboo, pointing to the nuget.exe file (if you don't have it you could download from https://www.nuget.org/
Create a New Command Task with the executable your created on the previous step.
On the Argument field: "restore YourSolution.sln"
In my approach I am using a VisualStudio task and after this one a MSTest Runner task.
When using Nuget with a source code repository, you have a couple of options.
1) check in your nuget executable to source code and create a bamboo command task that calls that location relative to the build directory, ${bamboo.build.working.directory}\tools\Nuget.exe.
2) Install the Nuget exe directly on the build server. Then you can create a new executable on Bamboo that you can reference in any task.
To create a new executable for use in tasks, use this - https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability
I guess you are using NuGet?
If so, you need to enable NuGet Package restore, because MSBuild does not know how to resolve these NuGet packages. This will create a .nuget directory in your solution which needs to be pushed the repository bamboo uses for the build.
Second problem I encountered when configuring the NUnit test runner with bamboo: the nunit-console.exe uses .NET Framework 3.5 which was not installed on my build server.