Reputation: 2460
I am trying to get a new solution to build on our tfs server, I get tons of errors here are few examples:
App_Start\BundleConfig.cs (1,18): errorCS0234: The type or namespace name 'Optimization' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) App_Start\FilterConfig.cs (1,18): errorCS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) App_Start\RouteConfig.cs (1,18): errorCS0234: The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) App_Start\WebApiConfig.cs (1,7): errorCS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) App_Start\WebApiConfig.cs (2,18): errorCS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)
For trouble shooting I am using MSBuild: C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe
The solution is set to compile in .net 4.7.2.
If I run the MSBuild command line locally it builds just fine, on the server if fails with above errors. I am not sure what I am missing. It also builds fine in visual studio 2019 locally.
I have checked my references that are part of any nuget packages and they pointing to the dll in the package location. i.e.
C:\somepath\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll
Any ideas?
EDIT: I added the build.proj file to restore nuget packages:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)src\</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
</PropertyGroup>
<ItemGroup>
<Solution Include="DCOAPI.sln">
<AdditionalProperties>OutDir=$(OutDir);Configuration=$(Configuration)</AdditionalProperties>
</Solution>
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Clean">
<MSBuild Targets="Clean"
Projects="@(Solution)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="@(Solution)" />
</Target>
<Target Name="Rebuild" DependsOnTargets="RestorePackages">
<MSBuild Targets="Rebuild"
Projects="@(Solution)" />
</Target>
</Project>
I get this message:
All packages listed in packages.config are already installed.
when building via MSBuild and two of the my project build, but the web api v2 proj does not build and I get all the errors like above.
These are the pertinent packages:
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net472" />
<package id="bootstrap" version="3.4.1" targetFramework="net472" />
<package id="jQuery" version="3.3.1" targetFramework="net472" />
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net472" />
<package id="Microsoft.AspNet.WebApi" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net472" />
<package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net472" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net472" />
<package id="Modernizr" version="2.8.3" targetFramework="net472" />
<package id="Newtonsoft.Json" version="11.0.1" targetFramework="net472" />
<package id="WebGrease" version="1.6.0" targetFramework="net472" />
</packages>
The only thing I added to the server was VS2019 bare bones:
Do I need to install anything else maybe?
Upvotes: 2
Views: 1524
Reputation: 2460
I had to update the Nuget.exe I was using from 2.8.6 to to the latest 5.1, so it could build the newtonsoft dll.
Then I had to manually copy the packages from local to the server at (not sure why they were not getting added automatically):
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages
Also, as mentioned by LanceLiMSFT, I had to update VS to include asp.net and web development workload.
After all this I was able to get the solution to build via command line using MSBuild.
I am still having an issue getting CCNet to build the solution.
EDIT: I may need to add a step in the CCNet config to delete the packages folder before building. For whatever reason that seems to be key, when building via MSBuild
EDIT: also per LanceLiMSFT suggestion deleting the packages on the build server allowed the MSBuild command to work.
EDIT: was able to get CCNet to build by updating the build.proj file as such:
<Target Name="RemoveDirectories">
<Delete Files="C:\pathtopackages\packages\**\*" />
<RemoveDir Directories="C:\pathtopackages\packages\" />
</Target>
<Target Name="RestorePackages" DependsOnTargets="RemoveDirectories">
<Exec Command=""NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
Upvotes: 1
Reputation: 28216
1.You can try deleting those packages and then reinstall them. Similar issue see here. (Deleting packages and reinstall can avoid situation like All packages listed in packages.config are already installed.
)
2.As you mentioned above, it's a web api v2 project. I create one and find it should and will automatically add reference to Newtonsoft.Json
package, but it seems your packages.config
doesn't include this reference. Did you modified the packages.config file?
Maybe you should reference the Newtonsoft.Json package to resolve the error The type or namespace name 'Newtonsoft' could not be found
.And for packages.config format, you should both the packages.config and xx.csproj file, so I suggest you do this in VS IDE using Nuget Manager UI.
3.Also, if the packages are installed successfully but still get the error. You may need to check the content in your xx.csproj file which throws the CS0234 error messages. Check if their hint path are correct.
And for Configuration of the msbuild, you need to make sure the VS your server uses have installed the asp.net and web development workload.
Upvotes: 1