MSBuild /p:AdditionalLibPaths is not working as expected - msbuild

Scenario:
I'm trying to Compile/Build a .Net c# application using MSBuild in Jenkins. I want the MSBuild to look at a given location for all the Dependent DLLs and use them instead of the ones referenced in the project.
Project file has : (which should be ignored and replaced with the path given in the command line below)
<Reference Include="T">
<HintPath>..\..\SharedLib\Unstable\T.dll</HintPath>
</Reference>
Desired behavior:
Override the project level setting (C:\Testing\SharedLib\Unstable) and use the dlls that are in C:\Testing\SharedLib\Stable when compiled from Jenkins MSBuild using the command line .
My Attempt:
msbuild C:\Testing\TestMSBuild\TestMSBuild.sln /p:AdditionalLibPaths="C:\Testing\SharedLib\Stable"
Console Output Log:

Related

disable web.config generation for asp.net core 3.1 project

The dotnet publish command for my ASP.NET Core 3.1 project creates a web.config file in my publish/ directory. I don't want this file to be generated (or copied to that folder, at least) - it is never to be used with IIS at all.
When I took a look at the command output with verbosity increased, I found the following text:
Target "_TransformWebConfig" in file "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "C:\repos\reportweb\reportweb\reportweb.csproj" (target "_AspNetCoreProjectSystemPostPublish" depends on it):
Using "TransformWebConfig" task from assembly "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Publish\targets\..\tools\netcoreapp2.1\Microsoft.NET.Sdk.Publish.Tasks.dll".
Task "TransformWebConfig"
Configuring the following project for use with IIS: 'C:\repos\reportweb\reportweb\bin\Release\netcoreapp3.1\linux-x64\publish\'
Updating web.config at 'C:\repos\reportweb\reportweb\bin\Release\netcoreapp3.1\linux-x64\publish\web.config'
Configuring project completed successfully
Done executing task "TransformWebConfig".
Done building target "_TransformWebConfig" in project "reportweb.csproj".
Is it somehow possible to configure my project to skip the _TransformWebConfig Target or TransformWebConfig Task - or to use another way to skip the generation? I know I could make MSBuild delete the file afterwards, but having this disabled seems less hacky to me.
You can control this with the IsWebConfigTransformDisabled MSBuild property:
To prevent transformations of the web.config file, set the MSBuild property $(IsWebConfigTransformDisabled):
dotnet publish /p:IsWebConfigTransformDisabled=true
Because this is an MSBuild property, you can also set it in the .csproj, instead of passing it as a command-line argument:
<PropertyGroup>
<IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
</PropertyGroup>

MSBuild /t:Pack with a .nuspec file - does it support token replacement? [duplicate]

I know Since the release of msbuild 15 (vs 2017) that NuGet is now fully integrated into MSBuild.
I have a nuspec file with defining variables of package properties like:
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$authors$</authors>
...
</metadata>
The nuspec file is located in the same folder of the project.
When using nuget tool to create the package , it works fine.
nuget pack
When using msbuild v15, it raise an exception.
run the command:
msbuild -version
Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework
15.8.168.64424
msbuild /t:pack /p:configuration=release /p:NuspecFile=mylib.nuspec
raise exception:
C:\Program Files\dotnet\sdk\2.1.402\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(199,5): error : Value cannot be null or an empty string.
The strange is that dotnet sdk version 2.1.402 raises the exception.
I tried msbuild installed with vs2017 with its path and also it raises the same exception.
When i substitute the variables with its values, msbuild is working fine.
The question
Is this a bug in msbuild version 15.8.168.64424 or i missed something ?
In other words, Can msbuild support using the metadata variables of the package?.
As has been mentioned in the comments, you no longer need a Nuspec file as most aspects can be controlled via properties in the csproj file or additional metadata on items (e.g. if you need additional content).
If you do need a nuspec file for some reason, you need to provide the variables for substitution yourself. You can do this in a target inside the csproj file like this:
<Target Name="SetNuspecProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>$(NuspecProperties);id=$(AssemblyName)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);config=$(Configuration)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);version=$(PackageVersion)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);description=$(Description)</NuspecProperties>
<NuspecProperties>$(NuspecProperties);authors=$(Authors)</NuspecProperties>
</PropertyGroup>
</Target>

msbuild: how to build and run a console application within the build and have it write output files to the output directory of another project?

I have three projects, I will call them ProjectSource, ProjectProcessor and ProjectTarget
ProjectSource is a .NET Standard 2.0 library producing a DLL.
ProjectProcessor is a .NET Core 2.1 console library. ProjectProcessor has a project reference on ProjectSource. It loads the ProjectSource DLL and based on some types it finds in there generates some output files (lets just say they are documentation). The number of files it produces can change over time.
ProjectTarget is a .NET Framework 4.7.1 console application. It has a dependency on ProjectSource, but also needs to include the content output by ProjectProcessor.
All projects are our code so we could change them quite a bit.
My question is, what is the right way to get the content output files of ProjectProcessor written to the output directory of ProjectTarget?
Approach 1: One approach that did not work was to use project reference in ProjectTarget to ProjectProcessor. It produced a build error that a .NET Framework 4.7.1 console application referencing a .NET Core 2.1 console library. I wouldn't want all the project output copied anyway, just the generated documentation files. I did try a ProjectReference with ReferenceOutputAssembly="false" and OutputItemType="Content".
Approach 2: Another approach is to have a pre or post build step on ProjectTarget that calls the ProjectProcessor console application, passing in the
current target directory (of ProjectTarget). For example:
<PropertyGroup>
<PreBuildEvent>dotnet $(SolutionDir)projects\ProjectProcessor\$(OutDir)netcoreapp2.1\ProjectProcessor.dll $(TargetDir)</PreBuildEvent>
</PropertyGroup>
This works, with the unfortunat downside that it doesn't recognize when it needs to run (I think it'd always run?). If ProjectSource or
ProjectProcessor have code changes I'd like it to run again, but not otherwise. (based on MSBuild copy output from another project into the output of the current project)
Approach 3: Finally, googling led me to try adding a target like this:
<Target Name="GenerateDocumentationContent" BeforeTargets="AfterBuild">
<MSBuild Projects="..\ProjectProcessor\ProjectProcessor.csproj" BuildInParallel="false" Targets="Build">
<Output TaskParameter="TargetOutputs" ItemName="DocumentationOutputDir" />
</MSBuild>
<Exec Command="dotnet #(DocumentationOutputDir) $(TargetDir)"/>
</Target>
This builds the ProjectProcessor project as expected and calls the resulting console application with the right parameters. But it doesn't run in the case that ProjectTarget doesn't have changes and I want it to run if ProjectSource and ProjectProcessor have changes.

How to use msbuild command line to create a bundle but exclude test projects

I have a C# solution with VS 2017, containing an app project and a test project. I can use the "create app package" wizard to create one single bundle for x86 and x64. However, I would like to automate this process, which means I need to use msbuild in command line to do the same work.
With the reference from here and here, I got:
msbuild .\MyProject.sln /p:AppxBundle=Always /p:AppxBundlePlatforms="x86|x64" /p:Configuration=Debug
But I will get errors for my test projects, like:
MakeAppx : error : Error info: error 80080204: The package with file name "Tests.XXXX.Shared.Uwp_1.0.0.0_x86_Debug.appx" and package full name "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx_1.0.0.0_x86__xxxxxxxxxxx" is not valid in the bundle because it has a different package family name than other packages in the bundle. The expected package name is xxxx-Test.xxxxTestApp....
My guess is that I should not use "Always" for AppxBundle, but I cannot find any document online mentioning how to set this value as "If Needed". I also tried to add "Never" in project properties for the test project, but the command line argument seems to overwrite that.
So my question is: How to exclude a test project from the solution when creating a bundle using msbuild in the command line?
How to exclude a test project from the solution when creating a bundle using msbuild in the command line?
To resolve this issue, you can build the project file directly when you create a bundle using MSBuild in the command line:
msbuild .\YourProjectFile.csproj /p:AppxBundle=Always /p:AppxBundlePlatforms="x86|x64" /p:Configuration=Debug
Alternatively, you can open test project file and add the following properties at the end of the first <PropertyGroup> element to exclude the test project to be included:
<PropertyGroup>
<AppxBundle>Never</AppxBundle>
</PropertyGroup>
Check this thread and the document for some more details.
Hope this helps.

MSBUILD error where folder contains more than one solution file

I'm trying to set up CCNET and I've run into a problem.
My builds are failing and I'm getting this error
MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.
In my configuration file ccnet.config my msbuild block is as follows
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>C:\example\directory</workingDirectory>
<projectFile>ExampleSolution.sln</projectFile>
<buildArgs>/noconsolelogger /v:quiet
/p:Configuration=Debug
/p:ReferencePath="C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\"
</buildArgs>
<targets>ReBuild</targets>
<timeout>600</timeout>
</msbuild>
In this case, C:\example\directory has multiple solution files. Even though I specified the project file I'm still getting that error.
You should specify what to build in the sln group.
msbuild SlnFolders.sln /t:NotInSolutionfolder:Rebuild;NewFolder\InSolutionFolder:Clean
So in CC.NET, add the /t parameter in the <buildArgs> tag.
Reference : http://msdn.microsoft.com/en-us/library/ms164311.aspx