devenv build fails for WPF application when invoked with nuget restore with msbuild /restore - msbuild

I am using msbuild /restore to retore the packages and then invoked devenv to build the solution. The commands are included in a batch file and this file is integrated to CI pipeline. The batch commands are as shown below.
_
msbuild MySolution.sln -t:Restore
"%VS160COMNTOOLS%..\IDE\devenv" "MySolution.sln" /build "%Build%|x64" /out MySolution.log
if errorlevel 1 goto :failed_
'MySolution.sln' includes two projects- a library project and a WPF application. The packages referenced in the projects are specified in a Packages.props file.
The build results are inconsistent. Sometimes it fails with following errors.
CSC : error CS2001: Source file
'\obj\DDLStyleEditor\Views\ElementGroupView.g.cs' could not be found.
CSC : error CS2001: Source file
'\obj\DDLStyleEditor\Views\OptionsView.g.cs' could not be found. CSC :
error CS2001: Source file
'\obj\DDLStyleEditor\Views\PropertiesView.g.cs' could not be found.
CSC : error CS2001: Source file
'\obj\DDLStyleEditor\Views\MainView.g.cs' could not be found.
It works fine with VS2019, the packages are properly restored and the solution build successfully. Then why does it fail with batch file??. Please help.

Related

CMake Error: Cannot open file for write: C:/Program Files/vtk/bin/CMakeCache.txt.tmpc3fcf for VTK

I am trying to build VTK version 9.2.2 with CMake for a few days now, but no luck so far. I am getting the below error in CMake GUI:
CMake Error: Cannot open file for write: C:/Program Files/vtk/bin/CMakeCache.txt.tmpc3fcf
CMake Error: Unable to (re)create the private pkgRedirects directory:
C:/Program Files/vtk/bin/CMakeFiles/pkgRedirects
CMake Error: : System Error: No such file or directory
CMake Error: Unable to open cache file for save. C:/Program Files/vtk/bin/CMakeCache.txt
CMake Error: : System Error: No such file or directory
I am following the video here, but it still does not work for me. I have tried to search for answers for a while, but there doesn't seem to be the exact same error that I am having on the internet anywhere.
I am on Windows 10, using VTK 9.2.2 and my CMake version is 3.25.1. I also tried with multiple versions of visual studio in the configuration, but it returned the same error.
The steps I have taken were:
Download VTK from the site
Put the downloaded files into the program files directory
Made a /src and /bin folder under a /vtk folder, which is outside the downloaded package
Copied and pasted the downloaded files into the /src folder
Opened CMake GUI and chose the src folder as the source and chose the bin folder as the build folder
Clicked generate and it threw the errors above
The error message like
CMake Error: Cannot open file for write: ...
usually occurred when CMake has no permissions to write a given file.
Your case involves directories under C:/Program Files/, which are usually configured as read-only for normal users.
The file CMakeCache.txt is created in the build directory, so the error message about such file usually means problem with a build directory.
A build directory should always be writable by the regular user. Here CMake creates files for the build tool, and here a build tool creates intermediate and resulted files.

Error compile Visual Studio 2019 Project dll with MSBuild 2019, obfuscating with Eazfuscator NET 2018.2 in TeamCity 2020.2.2

I have this error when TeamCity Build Step compile with obfuscating a Visual Studio dll Project with MSBuild:
EXEC: error: Error occurred during processing of input file '.dll' -> Cannot load file or assembly 'zx_2cba06c4237a413ea1e8116e71ad61dc, PublicKeyToken = 6205972ab2f0fc68' or one of its dependencies. The system cannot find the specified file. C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets (5473,5): error MSB3073: The command "if /I "Release" == "Release" "C:\Program Files (x86)\Eazfuscator.NET\Eazfuscator.NET.exe" "E:\Builds\MyDll\bin\Release\MyDll.dll" --msbuild-project-path "E:\Builds\MyDll\MyDll.csproj" --msbuild-project-configuration "Release" --msbuild-project-platform "AnyCPU" --msbuild-solution-path "*Undefined*" -n --newline-flush -v 2018.2" exit with code 1.
Eazfuscator-.NET-2018.2.2 is not compatible with MSBuild 2019, the solution is use Eazfuscator-.NET-2019.1 as minimun version.

How to build sonarscanner ,getting "MSbuild.exe is not recognize as internal and external command"?

I have installed Msbuild along with studio2017 but while building sonarscanner the msbuild.exe not found error thrown.

Continuous Integration with .Net Core App and Database Project (VS2017)

I have a .net Core app in VS2017 that also has a Database Project in the solution as well.
I want to set up continuous integration within Visual Studio Team Services to Build and Publish both the app and the database project. I have been able to get either the database project or app in the Publish Artifacts, but can't get them both at the same time. I am assuming I have set up my paths up wrong, but I have not had an luck with any of the combinations I have tried and there is very little documentation that I can find on having both an .net core app and a database project build and deploy together. How do I build and publish both the .net core app and the database project together in VSTS?
Below is the current set up I have in VSTS for the Build. I currently was trying to put the database project in one folder ($(build.artifactstagingdirectory)) and the app in another folder since resulted in
List of current steps
Below is the output from the current setup as seen in the image above
Starting: Build
******************************************************************************
Task : .NET Core
Description : Build, test and publish using dotnet core command-line.
Version : 1.0.2
Author : Microsoft Corporation
"C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\DatabaseDeploymentTest.web\DatabaseDeploymentTest.web.csproj --configuration release
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
DatabaseDeploymentTest.web -> d:\a\1\s\DatabaseDeploymentTest.web\bin\release\netcoreapp1.1\DatabaseDeploymentTest.web.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:07.50
Finishing: Build
Starting: Build solution **/*.sln
******************************************************************************
Task : MSBuild
Description : Build with MSBuild
Version : 1.120.0
Author : Microsoft Corporation
"D:\a_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.0\ps_modules\MSBuildHelpers\vswhere.exe" -version [15.0,16.0) -latest -format json
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "d:\a\1\s\DatabaseDeploymentTest.sln" /nologo /nr:false /dl:CentralLogger,"D:\a_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=|SolutionDir=d:\a\1\s"*ForwardingLogger,"D:\a_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.0\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /t:build /p:CmdLineInMemoryStorage=True /p:_MSDeployUserAgent="VSTS_8786b412-4ab0-4ae3-aa96-af0394363b64_build_32_835"
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 8/7/2017 6:40:49 PM.
Project "d:\a\1\s\DatabaseDeploymentTest.sln" on node 1 (build target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "d:\a\1\s\DatabaseDeploymentTest.sln" (1) is building "d:\a\1\s\DatabaseDeploymentTest\DatabaseDeploymentTest.sqlproj" (2) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Debug\".
Creating directory "obj\Debug\".
CoreCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\DatabaseDeploymentTest.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Team Tools\Static Analysis Tools\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /warnaserror- /utf8output "d:\a_temp.NETFramework,Version=v4.5.2.SqlClrAttributes.cs"
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn
SqlBuild:
Creating a model to represent the project...
Loading project references...
Loading project files...
Building the project model and resolving object interdependencies...
Validating the project model...
Writing model to d:\a\1\s\DatabaseDeploymentTest\obj\Debug\Model.xml...
DatabaseDeploymentTest\dbo\Stored Procedures\LoadEmployees.sql(1,1): Warning SQL71558: The object reference [dbo].[Employees].[HKSEmployeeId] differs only by case from the object definition [dbo].[Employees].[HKSEmployeeID].
d:\a\1\s\DatabaseDeploymentTest\dbo\Stored Procedures\LoadEmployees.sql(1,1,1,1): Build warning SQL71558: The object reference [dbo].[Employees].[HKSEmployeeId] differs only by case from the object definition [dbo].[Employees].[HKSEmployeeID]. [d:\a\1\s\DatabaseDeploymentTest\DatabaseDeploymentTest.sqlproj]
CopyFilesToOutputDirectory:
Copying file from "obj\Debug\DatabaseDeploymentTest.dll" to "bin\Debug\DatabaseDeploymentTest.dll".
DatabaseDeploymentTest -> d:\a\1\s\DatabaseDeploymentTest\bin\Debug\DatabaseDeploymentTest.dll
Copying file from "obj\Debug\DatabaseDeploymentTest.pdb" to "bin\Debug\DatabaseDeploymentTest.pdb".
SqlPrepareForRun:
DatabaseDeploymentTest -> d:\a\1\s\DatabaseDeploymentTest\bin\Debug\DatabaseDeploymentTest.dacpac
Done Building Project "d:\a\1\s\DatabaseDeploymentTest\DatabaseDeploymentTest.sqlproj" (default targets).
Project "d:\a\1\s\DatabaseDeploymentTest.sln" (1) is building "d:\a\1\s\DatabaseDeploymentTest.web\DatabaseDeploymentTest.web.csproj" (3) on node 1 (default targets).
PrepareForBuild:
Creating directory "bin\Debug\netcoreapp1.1\".
Creating directory "obj\Debug\netcoreapp1.1\".
PreComputeCompileTypeScript:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.2\tsc.exe --noEmitOnError --listEmittedFiles
CompileTypeScript:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.2\tsc.exe --noEmitOnError --listEmittedFiles
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705 /nostdlib+ /errorreport:prompt /warn:4 /define:TRACE;DEBUG;NETCOREAPP1_1 /reference:C:\Users\buildguest.nuget\packages\microsoft.applicationinsights.aspnetcore\2.0.0\lib\netstandard1.6\Microsoft.ApplicationInsights.AspNetCore.dll /reference:C:\Users\buildguest.nuget\packages\microsoft.applicationinsights\2.2.0\lib\netstandard1.5\Microsoft.ApplicationInsights.dll /reference:C:\Users\buildguest.nuget\packages\microsoft.aspnetcore.antiforgery\1.1.1\lib\netstandard1.3\Microsoft.AspNetCore.Antiforgery.dll /reference:C:\Users\buildguest.nuget\packages\microsoft.aspnetcore.authorization\1.1.1\lib\netstandard1.3\Microsoft.AspNetCore.Authorization.dll /reference:C:\Users\buildguest.nuget\packages\microsoft.aspnetcore.cors\1.1.1\lib\netstandard1.3\Microsoft.AspNetCore.Cors.dll /reference:C:\Users\buildguest.nuget\packages\microsoft.aspnetcore.cryptography.internal\1....
Using shared compilation with compiler from directory: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn
GetTypeScriptCopyToOutputDirectoryItems:
Adding items with BuildAction=TypeScriptCompile to the same collections that will be populated (with items of other BuildActions) by the GetCopyToOutputDirectoryItems target
CopyFilesToOutputDirectory:
Copying file from "obj\Debug\netcoreapp1.1\DatabaseDeploymentTest.web.dll" to "bin\Debug\netcoreapp1.1\DatabaseDeploymentTest.web.dll".
DatabaseDeploymentTest.web -> d:\a\1\s\DatabaseDeploymentTest.web\bin\Debug\netcoreapp1.1\DatabaseDeploymentTest.web.dll
Copying file from "obj\Debug\netcoreapp1.1\DatabaseDeploymentTest.web.pdb" to "bin\Debug\netcoreapp1.1\DatabaseDeploymentTest.web.pdb".
Done Building Project "d:\a\1\s\DatabaseDeploymentTest.web\DatabaseDeploymentTest.web.csproj" (default targets).
Done Building Project "d:\a\1\s\DatabaseDeploymentTest.sln" (build target(s)).
Build succeeded.
"d:\a\1\s\DatabaseDeploymentTest.sln" (build target) (1) ->
"d:\a\1\s\DatabaseDeploymentTest\DatabaseDeploymentTest.sqlproj" (default target) (2) ->
(SqlBuild target) ->
d:\a\1\s\DatabaseDeploymentTest\dbo\Stored Procedures\LoadEmployees.sql(1,1,1,1): Build warning SQL71558: The object reference [dbo].[Employees].[HKSEmployeeId] differs only by case from the object definition [dbo].[Employees].[HKSEmployeeID]. [d:\a\1\s\DatabaseDeploymentTest\DatabaseDeploymentTest.sqlproj]
1 Warning(s)
0 Error(s)
Time Elapsed 00:00:12.94
Finishing: Build solution **/*.sln
Starting: Copy Files to: $(build.artifactstagingdirectory)
******************************************************************************
Task : Copy Files
Description : Copy files from source folder to target folder using match patterns (The match patterns will only match file paths, not folder paths)
Version : 2.117.0
Author : Microsoft Corporation
found 0 files
Finishing: Copy Files to: $(build.artifactstagingdirectory)
Starting: Publish
******************************************************************************
Task : .NET Core
Description : Build, test and publish using dotnet core command-line.
Version : 1.0.2
Author : Microsoft Corporation
"C:\Program Files\dotnet\dotnet.exe" publish d:\a\1\s\DatabaseDeploymentTest.web\DatabaseDeploymentTest.web.csproj --configuration release --output d:\a\1\a\DatabaseDeploymentTest.web
Microsoft (R) Build Engine version 15.1.1012.6693
Copyright (C) Microsoft Corporation. All rights reserved.
DatabaseDeploymentTest.web -> d:\a\1\s\DatabaseDeploymentTest.web\bin\release\netcoreapp1.1\DatabaseDeploymentTest.web.dll
Finishing: Publish
Starting: Publish Artifact
******************************************************************************
Task : Publish Build Artifacts
Description : Publish Build artifacts to the server or a file share
Version : 1.120.1
Author : Microsoft Corporation
Async Command Start: Upload Artifact
Uploading 1 files
File upload succeed.
Upload 'd:\a\1\a' to file container: '#/677588/DatabaseDeploymentTest'
Associated artifact 724 with build 835
Async Command End: Upload Artifact
Finishing: Publish Artifact
Specify $(build.sourcesdirectory) in Source Folder and **\*.dacpac in Contents of Copy files task.

Batch Scripting - dump msbuild output to a specific file instead of to the console window if successful?

I'm not sure how to do this. I have a batch script file I am using to do multiple msbuild calls. I don't want the msbuild output to pollute my command window, but instead I want it to dump into a log file. I'm not sure how to do this, but here's my script so far:
#ECHO Building shared libraries ...
msbuild "SharedLibraries.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:: Copy dll files to specific location
#ECHO Building primary application...
msbuild "Myapp.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:ERROR
So, how do I:
Dump the msbuild output to a log file?
Catch unsuccessful builds and go to the error label?
Adding the /fileLogger command line switch causes MSBuild to write the build output to file msbuild.log in the current directory, while the /noconsolelogger switch causes MSBuild to no longer write to standard output. The filename can be set using the /flpswitch as in the following example:
msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=buildlog.txt
See MSBuild Command Line Reference for details.
Regarding your second question; MSBuild returns a non-zero exit code if the build failed, which can be processed as usual:
msbuild "SharedLibraries.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=SharedLibraries.log
if not errorlevel 0 goto ERROR
msbuild "Myapp.sln" /nologo /noconsolelogger /fileLogger /flp:logfile=Myapp.txt
if not errorlevel 0 goto ERROR
:ERROR