What could I be doing wrong with my msbuild argument? - msbuild

I have an msbuild argument
/t:Project.HQ.Web /p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\"
in my Azure DevOps Build pipeline for Solution Build.
I get an error that says
Agent job 1: "Code\AnotherMutliProjSolution.sln(0,0): Error MSB4014:
The build stopped unexpectedly because of an internal failure.
System.ArgumentException: The name "Project.HQ.Web" contains an
invalid character ".". at
Microsoft.Build.Shared.ErrorUtilities.ThrowArgument(Exception
innerException, String resourceName, Object[] args) at
Microsoft.Build.Construction.ProjectTargetElement.set_Name(String
value) at
Microsoft.Build.Construction.ProjectTargetElement.CreateDisconnected(String
name, ProjectRootElement containingProject) at
Microsoft.Build.Execution.ProjectTargetInstance.ToProjectTargetElement(ProjectRootElement
rootElement) at
Microsoft.Build.Execution.ProjectInstance.ToProjectRootElement() at
Microsoft.Build.Construction.SolutionProjectGenerator.CreateSolutionProject(String
wrapperProjectToolsVersion, Boolean explicitToolsVersionSpecified) at
Microsoft.Build.Construction.SolutionProjectGenerator.Generate() at
Microsoft.Build.Execution.ProjectInstance.GenerateSolutionWrapper(String
projectFile, IDictionary2 globalProperties, String toolsVersion,
ILoggingService loggingService, BuildEventContext
projectBuildEventContext, IReadOnlyCollection1 targetNames,
ISdkResolverService sdkResolverService, Int32 submissionId) at
Microsoft.Build.Execution.ProjectInstance.LoadSolutionForBuild(String
projectFile, PropertyDictionary1 globalPropertiesInstances, String
toolsVersion, BuildParameters buildParameters, ILoggingService
loggingService, BuildEventContext projectBuildEventContext, Boolean
isExplicitlyLoaded, IReadOnlyCollection1 targetNames,
ISdkResolverService sdkResolverService, Int32 submissionId) at
Microsoft.Build.Execution.BuildManager.LoadSolutionIntoConfiguration(BuildRequestConfiguration
config, BuildRequest request) at
Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node,
BuildRequestBlocker blocker) at
Microsoft.Build.Execution.BuildManager.IssueRequestToScheduler(BuildSubmission
submission, Boolean allowMainThreadBuild, BuildRequestBlocker
blocker)" Review
I have tried having a my target set as 'Project.HQ.Web' and "Project.HQ.Web". I still run into the same issues.

You need to replace the . with underscores to build the generated solution targets:
msbuild /t:Project_HQ_Web
See the following part of How to: Build specific targets in solutions by using MSBuild.exe
Specify the target after the -target: switch in the format
<ProjectName>:<TargetName>. If the project name contains any of the
characters %, $, #, ;, ., (, ), or ', replace them with an _ in the
specified target name.

From the documentation, /t is used to build target of a project. There is no switch for the project itself.
You must use as command line:
msbuild.exe /p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactstagingdirectory)\\" "Project.HQ.Web"

I finally figured it out.
What I did was instead of build the solution,
I built the csproj file itself passing in the msbuild argument
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(build.stagingDirectory)\\ProjectHQWeb

Related

Error while Building (compile) wixproj using MSBuild api 15.9.20

I'm using wix in a project and i have a specific need :
Build wixproj using MSBuild from c#.
For that i'm using MSBuild api as folowing :
static void Main(string[] args)
{
string toolsPath = ToolLocationHelper.GetPathToBuildToolsFile("msbuild.exe", ToolLocationHelper.CurrentToolsVersion);
ProjectCollection projectCollection = new ProjectCollection();
projectCollection.AddToolset(new Toolset(ToolLocationHelper.CurrentToolsVersion, Path.GetDirectoryName(toolsPath), projectCollection, string.Empty));
Project project = projectCollection.LoadProject("TestWix.wixproj");
var result = project.Build(new ConsoleLogger());
Console.ReadKey();
}
And i get this error :
C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix2010.targets(1988,5): error MSB4127: The "GenerateCompileWithObjectPath" task could not be instantiated from the assembly "C:\Program Files (x86)\WiX Toolset v3.11\bin\WixTasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Tools.WindowsInstallerXml.Build.Tasks.GenerateCompileWithObjectPath' to type 'Microsoft.Build.Framework.ITask'.
But when i use msbuild command line it's work fine.
Do you have any idea please ?
Thank you in advance.

Using XAML UpgradeTemplate with TFS 2015 \ 2017

I ran into this issue upgrading from TFS 2013 to 2017. If you are still using the UpgradeTemplate.xaml to run old TFS 2005\2008 style MSBuild Team Builds (TFSBuild.proj) you will find that they do not work with the TFS 2015 or 2017 XAML build agent.
You will get this error when running the build due to some breaking changes that were introduced in the core assemblies. XAML builds have been deprecated for some time... and the old MSBuild based Team Builds are waaaayyyyy out of support. So Microsoft (rightfully) doesn't care.
But is there a way to get these builds working in TFS 2015\2017? It would be a big waste of time to convert these over to using XAML builds only to then convert them to the new build engine after upgrading to TFS 2017.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets (957): The following errors were encountered while processing the workflow tree:
'VisualBasicValue<LabelChildOption>': Compiler error(s) encountered processing expression "Microsoft.TeamFoundation.VersionControl.Client.LabelChildOption.Fail".
'LabelChildOption' is ambiguous in the namespace 'Microsoft.TeamFoundation.VersionControl.Client'.
'VisualBasicValue<RecursionType>': Compiler error(s) encountered processing expression "Microsoft.TeamFoundation.VersionControl.Client.RecursionType.Full".
'RecursionType' is ambiguous in the namespace 'Microsoft.TeamFoundation.VersionControl.Client'.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets (957): The "Label" task failed unexpectedly.
System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree:
'VisualBasicValue<LabelChildOption>': Compiler error(s) encountered processing expression "Microsoft.TeamFoundation.VersionControl.Client.LabelChildOption.Fail".
'LabelChildOption' is ambiguous in the namespace 'Microsoft.TeamFoundation.VersionControl.Client'.
'VisualBasicValue<RecursionType>': Compiler error(s) encountered processing expression "Microsoft.TeamFoundation.VersionControl.Client.RecursionType.Full".
'RecursionType' is ambiguous in the namespace 'Microsoft.TeamFoundation.VersionControl.Client'.
at System.Activities.Hosting.WorkflowInstance.ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager)
at System.Activities.Hosting.WorkflowInstance.RegisterExtensionManager(WorkflowInstanceExtensionManager extensionManager)
at System.Activities.WorkflowApplication.EnsureInitialized()
at System.Activities.WorkflowApplication.RunInstance(WorkflowApplication instance)
at System.Activities.WorkflowApplication.Invoke(Activity activity, IDictionary`2 inputs, WorkflowInstanceExtensionManager extensions, TimeSpan timeout)
at System.Activities.WorkflowInvoker.Invoke(Activity workflow, IDictionary`2 inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
at Microsoft.TeamFoundation.Build.Tasks.WorkflowTask.ExecuteInternal()
at Microsoft.TeamFoundation.Build.Tasks.Task.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()
You can work around this error if you don’t care about labeling your code as part of the build process or updating associated work items. In my case I was still using the UpgradeTemplate as a convenient way of performing a check-in based “Get-Latest” of source code in TFVC to the builds folder on the build machine… not really a “build” at all. So this was A-OK.
Set these two properties to true in your TFSBuild.proj
This will cause MSBuild to skip execution of the CoreLabel and the CoreGetChangesetsAndUpdateWorkItems targets. CoreLabel is the one which loads the task that is failing the build... and CoreGetChangesetsAndUpdateWorkItems needs the label to exist or it will also fail.
I found these properties by digging through the old C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets - which is the team build script that shipped with TFS 2005 \ 2008.
<SkipLabel>true</SkipLabel>
<SkipGetChangesetsAndUpdateWorkItems>true</SkipGetChangesetsAndUpdateWorkItems>

Gitlab CI pipeline SonarQube msbuild error ArgumentNullException: Value cannot be null

Is anyone familiar with this error and how to solve it? I'm using Sonarqube Scanner 2.3.1 and msbuild 12.0. The project is 4.5 framework.
Time Elapsed 00:00:39.12
$ SonarQube.Scanner.MSBuild.exe end
SonarQube Scanner for MSBuild 2.3.1
Default properties file was found at C:\SonarQube\bin\SonarQube.Analysis.xml
Loading analysis properties from C:\SonarQube\bin\SonarQube.Analysis.xml
sonar.verbose=true was specified - setting the log verbosity to 'Debug'
Post-processing started.
11:00:26.108 Using environment variables to determine the download directory...
11:00:26.188 11:00:26.188 sonar.verbose=true was specified - setting the log verbosity to 'Debug'
11:00:26.191 Loading the SonarQube analysis config from F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\conf\SonarQubeAnalysisConfig.xml
11:00:26.191 Not running under TeamBuild
11:00:26.191 Analysis base directory: F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube
Build directory:
Bin directory: F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\bin
Config directory: F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\conf
Output directory: F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\out
Config file: F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\conf\SonarQubeAnalysisConfig.xml
Generating SonarQube project properties file to F:\Gitlab-Runner\builds\1d3a7e33\1\folder\folder\folder\.sonarqube\out\sonar-project.properties
Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: key
at SonarQube.Common.ListPropertiesProvider.TryGetProperty(String key, Property& property)
at SonarQube.Common.AggregatePropertiesProvider.TryGetProperty(String key, Property& property)
at SonarQube.Common.AggregatePropertiesProvider.GetAllProperties()
at SonarScanner.Shim.PropertiesFileGenerator.GetAnalysisProperties(AnalysisConfig config)
at SonarScanner.Shim.PropertiesFileGenerator.GenerateFile(AnalysisConfig config, ILogger logger, IRoslynV1SarifFixer fixer)
at SonarScanner.Shim.SonarScannerWrapper.Execute(AnalysisConfig config, IEnumerable`1 userCmdLineArguments, ILogger logger)
at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.InvokeSonarScanner(IAnalysisPropertyProvider cmdLineArgs, AnalysisConfig config)
at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute(String[] args, AnalysisConfig config, ITeamBuildSettings settings)
at SonarQube.Bootstrapper.BootstrapperClass.PostProcess()
at SonarQube.Bootstrapper.BootstrapperClass.Execute()
at SonarQube.Bootstrapper.Program.Execute(String[] args, ILogger logger)
at SonarQube.Bootstrapper.Program.Main(String[] args)
ERROR: Job failed: exit status 3762504530
The problem is caused by the property called sonar.analysis.mode being set equal to "issues".
issues mode should never be used manually as it is used only by tools.
set your sonar.analysis.mode=[preview/publish]
(publish is default so you don't have to set the property at all if that's what you want.)

Running dotnet ef without Visual Studio throws an exception

I have a project that is a .NET Core console application with just a model and some seed data. On a development desktop I can go to the application directory, run dotnet ef database update and everything is fine (I need to copy appsettings.json to bin\... directory, but OK).
The problem is when I need to run this in the client environment (with VPN access, and without Visual Studio there). First, I am not sure what exactly I need to copy to the remote machine. But let's say, I copied the whole project. First, when I run, I get the following error:
Unhandled Exception: System.IO.DirectoryNotFoundException: Could not find a part of the path '.nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools'.
I have a directory .nuget\packages\Microsoft.EntityFrameworkCore.Tools but not under .tools. Out of despair I created .tools and copied this directory under it, but now I am getting the following exception:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromToolLibrary(LibraryRange toolLibraryRange, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveCommandSpecFromAllToolLibraries(IEnumerable`1 toolsLibraries, String commandName, IEnumerable`1 args, ProjectContext projectContext)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver. ResolveFromProjectTools(String commandName, IEnumerable`1 args, String projectDirectory)
at Microsoft.DotNet.Cli.Utils.ProjectToolsCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CompositeCommandResolver.Resolve (CommandResolverArguments commandResolverArguments)
at Microsoft.DotNet.Cli.Utils.CommandResolver.TryResolveCommandSpec(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Utils.Command.Create(String commandName, IEnumerable`1 args, NuGetFramework framework, String configuration, String outputPath)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
at Microsoft.DotNet.Cli.Program.Main(String[] args)
Clearly, my trial and error attempts to find the right way hit a wall. Is there some substantive (not just syntax) documentation as to how to run EF Core commands outside Visual Studio? .NET is version 1.1 if that matters
It seems that you have not removed Entity framework completly hence the error that path: .nuget\packages.tools\Microsoft.EntityFrameworkCore.Tools is not found.
Somewhere in code there must be a reference to this file. If you are using project.json try checking your tools and depenedencies for Microsoft.EntityFrameworkCore.Tools.
If you are using the .csproj SDK version. Check your project file for any of these references and remove them.

Why does including the msbuild OutputPath option cause MetadataWorkspace error when building Silverlight/WCF RIA sln?

[specific version numbers of items related to this issue are included at the end of the text]
When building the Foo.sln (SL4 with WCF/RIA services) with the following msbuild command:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild SNSC.sln /nologo /p:configuration=release /p:OutputPath=..\..\output\Foo /t:Rebuild
... I receive the following error:
"C:\SourceCode2\prod\current\Silverlight\Foo.sln" (Rebuild target) (1)
-> "C:\SourceCode2\prod\current\Silverlight\Foo.Web.Data\Foo.Web.Data.csproj"
(Rebuild target) (2) ->
"C:\SourceCode2\prod\current\Silverlight\Foo.Fha\Foo.Fha.csproj"
(default target) (3:2) -> (CreateRiaClientFiles target) ->
C:\Program Files
(x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Ria.Client.targets(303,5):
error : Failed to get the MetadataWorkspace for the DbContext type
'Foo.Web.Data.Fha.CoreDbContext'.
[C:\SourceCode2\prod\current\Silverligh t\Foo.Fha\Foo.Fha.csproj]
C:\Program Files
(x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Ria.Client.targets(303,5):
error : Failed to get the MetadataWorkspace for the DbContext type
'Foo.Web.Data.LoanCorrespondence.CoreDbContext'.
[C:\SourceCode2\prod\cur rent\Silverlight\Foo.Fha\Foo.Fha.csproj]
However, when I remove the OutputPath option (keeping the rest of the command the same):
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild SNSC.sln /nologo /p:configuration=release /t:Rebuild
...the build succeeds (albeit with 77 warnings). And of course it compiles with no issue in VS2010.
Why does the inclusion of the OutputPath option cause this exception?
Specifics:
* attempted on 2 different 64bit machines with same result
* win7 OS
* msbuild: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild
* Silverlight 4 with WCF RIA