MvcBuildViews ASPNETCOMPILER error ASPRUNTIME: Failed to map the path '/temp' - msbuild

My web project builds and works fine under Visual Studio 2017, but I'm having trouble creating a project in TeamCity.
MSBuild Error "ASPNETCOMPILER error ASPRUNTIME: Failed to map the path '/temp'" occured.
How to solve this problem?

So, I solved this problem in the TeamCity build, I use the MSBUILD builder like this:
Targets: Rebuild;Publish
Command line parameters for build and tests: /p:WebProjectOutputDir="%system.teamcity.build.workingDir%\Website"
You can then use the Website directory as your artifact.

Related

Why is the project file not found even though I am using an MSBuild task?

I created an Azure Devops build pipeline and I am trying to build my ASP.NET MVC and Angular hybrid site project on Bitbucket (git).
The project first gets checked out, and Nuget restores the necessary packages, however, I cannot get the .NET to build!
I've stumbled on this post here that basically advises against using the dotnet build task and recommended just using Visual Studio build or MSBuild tasks instead.
Nether are working for me though!
I tried VS2017-win2016 hosted agent, didn't work.
I tried Windows 2019 hosted agent, didn't work.
I am getting this error:
Bobby.ProjectA\Bobby.ProjectA.csproj(713,3): Error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.100\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.100\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.
Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1
Dotnet command failed with non-zero exit code on the following projects : D:\a\1\s\Bobby.ProjectA.Tests\Bobby.ProjectA.Tests.csproj,D:\a\1\s\Bobby.ProjectA\Bobby.ProjectA.csproj
D:\a\1\s\Bobby.ProjectA\BobbyProjectA\BobbyProjectA.sln.metaproj(0,0): Error MSB3202: The project file "D:\a\1\s\Bobby.ProjectA\BobbyProjectA\Bobby.ProjectA\Bobby.ProjectA.csproj" was not found.
D:\a\1\s\Bobby.ProjectA\BobbyProjectA\BobbyProjectA.sln.metaproj(0,0): Error MSB3202: The project file "D:\a\1\s\Bobby.ProjectA\BobbyProjectA\Bobby.ProjectA.Tests\Bobby.ProjectA.Tests.csproj" was not found.
Process 'msbuild.exe' exited with code '1'.
Since Ubuntu is faster, I also tried that, however, as expected Visual Studio build task fails with that since VS is not installed on the machine.
So I tried with MSBuild and that worked fine with Ubuntu, however, still getting same error that the project file was not found.
Project "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA/Bobby.ProjectA.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA.Tests/Bobby.ProjectA.Tests.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
Done Building Project "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" (default targets) -- FAILED.
Build FAILED.
"/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln" (default target) (1) ->
(Build target) ->
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA/Bobby.ProjectA.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln.metaproj : error MSB3202: The project file "/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/Bobby.ProjectA.Tests/Bobby.ProjectA.Tests.csproj" was not found. [/home/vsts/work/1/s/Bobby.ProjectA/BobbyProjectA/BobbyProjectA.sln]
I pretty much exhausted my searches and not sure how to solve this.
Here are some screenshots that show my pipeline tasks:
I also thought maybe x64 architecture would have something to do with it, but that didn't resolve the issue.
I've stumbled on some other interesting posts like this one, but I'm not sure what adding the project to source control means in the answer given, considering my csproj files are already hosted in the repo and being checked out before any tasks run.
My project structure and .sln path (project):
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bobby.ProjectA", "Bobby.ProjectA\Bobby.ProjectA.csproj", "{12345FE4-4CB9-3245-9A45-DB9A4AF1DFEB}"
Based on my test, I could reproduce the similar issue when the wrong csproj file path is mapped in the .sln file.
You could check your .sln file -> project field.
For example:
File structure
The .csproj file is under the WebApplication2 folder, so the project relative path is WebApplication2\WebApplication2.csproj.
.sln file
VisualStudioVersion = 16.0.30611.23
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication2", "WebApplication2\WebApplication2.csproj", "{497AD76F-222C-4BEB-BDCB-401B0E80B5CE}"
EndProject
Update:
After discussion with Cataster, the import Project issue can be resolved by specifying **/*.csproj in Msbuild task.
For example:

How to create Azure Cloud Service package from MsBuild in azure pipeline

I have some cloud service projects , which i am trying to get it into CI/CD. When i right click on the project from Visual Studio and click Package it does what i want. I can see the ServiceConfiguration.cscfg and ServiceDefinition.csdef in the bin\Release folder after the package command is completed.
How can i achieve the same from an MSBuild command line ? I have tried
msbuild.exe
/p:DeployTarget=Package
/p:DeployOnBuild=true
/p:AutomatedBuild=True
/p:configuration=release
/p:outdir="D:\Pub"
/p:targetprofile="Cloud"
/target:Publish
/p:SolutionDir=$/src/mysln/ WorkerRole.ccproj
What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ? Please advice
Edit : Also refered the official docs , could'nt find anything
Edit 2 : Looks like i can get the packages generated. Now the problem is doing this in VSTS. The build is failing with " projectfile="*Undefined*Obfuscator\Maps\
Basically the solution path is becoming as undefined
Edit 3 : Here's the error message when i try to build only the CloudServiceProj
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(5165,5): Error MSB3073: The command "if "Release" == "Debug" goto :exit
"*Undefined*Obfuscator\Tool\CO" projectfile="*Undefined*Obfuscator\Maps
The undefined is working fine locally , since it has the $(SolutionDir) variable in VS. Not sure how do i handle it here
Update
Here's the msbuild that am using
Update 4
I tried building the solution directly as suggested, but it has some .NET CORE as well as .NET Framework projects and i am getting this error
C:\Program Files\dotnet\sdk\2.2.105\Sdks\Microsoft.NET.Sdk.Publish\build\netstandard1.0\Microsoft.NET.Sdk.Publish.targets(163,11): Error MSB4006: There is a circular dependency in the target dependency graph involving target "Publish"..
What i get is the command completes and i can see around 241 dll and the required files in the folder. Am i missing something in the command argument ?
For this question, you can try to change the argument /p:outdir="D:\Pub" to /p:PublishDir="D:\Pub". That because the argument outdir is used to stored the output files not the publish files, it contains the build output of the projects (including the reference project). That the reason why there are around 241 dll and the required files in the folder.
As I test, if I change the argument to PublishDir, it works fine:
For the second question, I am not familiar with Azure Cloud Service, as I know about MSBuild/Visual Studio, we should build the "main" project instead of the reference project, so you can try to build the AzureCloudService.ccproj or build the solution file .sln.
Besides, when we build the project/solution, we do not need specify the solution folder, just specify the project file or solution directly:
msbuild.exe "TheRelativePathForYourSolutionInRepos.sln" /t:Publish /p:DeployOnBuild=true /p:AutomatedBuild=True /p:configuration=release /p:TargetProfile=Cloud /p:PublishDir="D:\Pub"
If above not resolve your questions, please share your build error log in your question.
Update:
For the second part, I have a post build event which does some
obfuscation .
If you have use any Macros, like $(SolutionDir) in your build event, but build the project file, you will got that error. Because the project reference information exists in the solution information, we can't access it when we only build one project.
Try to replace all $(SolutionDir) with $(ProjectDir)..\
Update2:
Since you can build the .sln file on your local without any issue, you could also build the .sln file with Azure pipeline. As test, I could build the .sln file in the Azure pipeline:
Besides, if you have replace $(SolutionDir) with $(ProjectDir)..\, how do you still get the error Undefined? Try to double check you build event, or you can share it in the question.
Hope this helps.

TeamCity error MSB3021: Unable to copy file

I have a TeamCity. I have setup build for my web project (csproj) with msbuild,
command line parameter is looks like
/p:Configuration=%env.Configuration% /p:outputpath=bin2
/p:DeployOnBuild=True /p:IsDesktopBuild=false
/p:DeployTarget=MSDeployPublish
/p:MsDeployServiceUrl=httppath
/p:AllowUntrustedCertificate=True /p:MSDeployPublishMethod=WMSVC
/p:UserName=xxx /p:Password=xxx
but build faild all the time with error:
Step 1/1: MSBuild (7s)
pathxxx\MyPortal.csproj.teamcity: Build target: Build (4s)
[pathxxx\MyPortal.csproj.teamcity] _CopyWebApplicationLegacy
[_CopyWebApplicationLegacy] Copy
[Copy] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(178, 5): error MSB3021: Unable to copy file "Bin\MyPortal.dll" to "bin2\_PublishedWebsites\MyPortal.csproj\Bin\MyPortal.dll". Could not find a part of the path 'Bin\MyPortal.dll'.
[Copy] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets(178, 5): error MSB3021: Unable to copy file "Bin\MyPortal.pdb" to "bin2\_PublishedWebsites\MyPortal.csproj\Bin\MyPortal.pdb". Could not find a part of the path 'Bin\MyPortal.pdb'.
[pathxxx\MyPortal.csproj.teamcity] Project pathxxx\MyPortal.csproj.teamcity failed.
[Step 1/1] Step MSBuild failed
if I removed /p:outputpath=bin2 parameter i see other king of error,
The OutputPath property is not set for project
'MyPortal.csproj.teamcity'. Please check to
make sure that you have specified a valid combination of Configuration
and Platform for this project. Configuration='TestEnv' Platform='Any
CPU'. You may be seeing this message because you are trying to build
a project without a solution file, and have specified a non-default
Configuration or Platform that doesn't exist for this project.
I am using xml transformation and I have make shure that TestEnv is exist in all project inside solution.
What it could be ? and how to fix it ?
Thanks.
have you added a configuration testenv to all your projects? as its missing the OutputPath property.Alternatively you could just add the property to your initial command e.g. /p:OutputPath=..\output .

How to build .vdproj using MSBuild task?

I get following error when I try the following command:
devenv.exe /build Debug SetupProject.vdproj
ERROR: Unable to update the dependencies of the project.
We use to build our Vdproject using devenv.exe. Devenv.exe will be wrapped into MSbuild exec task.
You can get reference from Msdn.
But your error is not relevant to msbuild problem

NAnt + MSBuild (4.0) == MSBuild launch failure w/directory not found error

Ive got CC.Net and NAnt (and MSBuild) running on a new VM-based build server (Win7-64 Pro).
CC.Net can call MSBuild just fine - but I run into problems there when dealing with project-scope builds. The conditionals just dont have what I need. Not even close.
So I decide to deal with those conditions by calling MSBuild with NAnt, which fails every time. When I run the nant script from the command prompt, I get this:
[loadtasks] Failure scanning "C:\nant\bin\extensions\common\2.0\Collection
Gen.dll" for extensions. Could not load file or assembly 'Microsoft.VSDesigner,
Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of
its dependencies. The system cannot find the file specified.
Buildfile: file:///c:/c7/projects/dyndata/dyndata.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: build
build:
[loadtasks] Scanning directory "c:\nantcontrib\bin\lib" for extension assemblies
.
[echo] Building DynData v7.0.7
BUILD FAILED
c:\c7\projects\dyndata\dyndata.build(24,12):
Failed to start MSBuild.
c:\c7\projects\dyndata\dyndata.build(24,12):
External Program Failed: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbui
ld.exe (return code was 1)
Total time: 0.4 seconds.
c:\c7\projects\dyndata\dyndata.build(24,12):
Failed to start MSBuild.
c:\c7\projects\dyndata\dyndata.build(24,12):
'C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe' failed to start.
The directory name is invalid
The Designer assembly is present on this machine, which has VS2010 Pro installed on it.
The build folder is correct.
The framework folder is correct.
Umpteen searches for nant/msbuild and this message have yielded nothing substantive.
These items have been tried and failed to change the results:
Nant msbuild task with .net 4.0 rc
.NET projects build automation with NAnt/MSBuild + SVN (tho I am using Vault)
I tried to build the nant code so I could debug the problem via VS2010's debugger but the source project is an unworkable mess and wont even begin to build.
Ideas are welcome:)
I think the first error about Microsoft.VSDesigner is just a warning - not a failure. On my developer box and build server I have VS2005 and VS2010 Pro installed and I do not have Microsoft.VSDesigner version 7 installed. I have version 8 and 9 installed but not 7.
It looks like the "build" target is running in nant and then then it fails. You are loading the tasks from nantcontrib then trying to start msbuild. How are you starting msbuild? Could you post the part of the nant file that starts it? What version of nant are you using? Does running nant with -v and -debug+ flags show anything helpful?