How to consume a VSTS artifact DLL from another pipeline in my VSTS MSTest pipeline - dll-injection

I am trying to use a DLL artifact from a developers build pipeline in my VSTS MSTest build pipeline. I need to reference this DLL but I get an error - Error CS0246: The type or namespace name 'Adv' could not be found (are you missing a using directive or an assembly reference?)
I am able to download the DLL's/Artifacts successfully to the agent using Download Build Artifacts option in my pipeline.
How can I get my build in the VSTS pipepline to use the downloaded DLL artifacts on the agent and get rid of this error?

I found out you need to use the copy files option to get the DLL's where you want them. I first tried \bin\debug but the problem there was the build creates these areas automatically and it overwrote my file copy. I noticed in the build log it was considering looking here for the DLL's - C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0.
I updated the copy files to copy there and the solution builds just fine now.

Related

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.

.net core msbuild nuget with additional assemblies

This sample shows a .NET Core project which can be packaged into a nuget package just using dotnet pack, and when restored in another project, it integrates in the msbuild pipeline. One of the great things about this sample is it creates a nuget package that integrates with msbuild on linux, mac and Windows. However, the custom build code doesn't have dependencies on any other assemblies.
How can I adapt this sample to use code that uses a dependency?
Here are my failed attempts:
Attempt 1
I added a package reference to Newtonsoft.Json and changed the code to do some JSON serialisation. However, in the project that uses the build nuget, when I do a dotnet publish, I get the following error:
error MSB4018: The "Zip" task failed unexpectedly. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. [C:\git\MSBuild-Features-With-Nate-McMaster\Video-2\1-NuGet\Web.csproj]
Additionally, if my project didn't already have a dependency on JSON.NET, adding the build nuget would unnecessarily add it.
Attempt 2
I used nuget.exe spec to create a .nuspec file. At the end of the file, I added:
<files>
<file src="bin\Release\**" target="build" />
<file src="build\**" target="build" />
</files>
However, both "dotnet pack" and "msbuild /t:pack" ignore the file, and nuget.exe pack fails with the error Unable to find 'bin\Release\0-WriteATask\bin\Release\'. Make sure the project has been built..
If I try nuget.exe pack Zipper.nuspec or msbuild /t:pack /p:NuspecFiles=Zipper.nuspec, they both fail with the message Value cannot be null or an empty string..
Attempt 3
I edited the nuspec to remove all of the placeholders that are normally calculated from the project (any string starting and ending with a $). Then, doing a nuget.exe pack Zipper.nuspec created a nupkg file, and the net46 folder contains Newtsonsoft.Json.dll, but the netstandard1.3 folder does not.
The way MSBuild loads a task assembly can make it tricky to load additional assemblies that you may depend on.
Typically, the easiest way to solve this is to ship a copy of your dependencies inside your NuGet package. But your dependencies alongside your task assembly file in the package. There may be some additional complications that require you to use AssemblyLoadContext or the AppDomain.AssemblyResolve event.
You can do this without a nuspec file by forcing MSBuild to copy your assemblies into the local build output, and then copying them into your package. Set CopyLocalLockFileAssemblies=true, and add the items to _PackageFiles
Here's an example of how to do that: https://github.com/madskristensen/BundlerMinifier/blob/3333b5c38289a247391966443370ee6f4a29bf26/src/BundlerMinifier/BundlerMinifier.csproj#L35-L47
Hopefully, this will be addressed in the future, https://github.com/Microsoft/msbuild/issues/1312, and the task assembly resolution will use the NuGet cache.
Try it with the 9.0.1 version of Newtonsoft.Json, it worked for me, all these dll load problems went away, and it still targets .NET Standard. Although I did copy all the dependencies next to the task dll, but with the 10.x version even that didn't help.

Build using TeamCity: Failed to start MSBuild; please specify a nuspec or project file to use

I'm trying to build a website in Teamcity, but the first build step "starting MSBuild" is failing.It seems that the command is trying to install nuget, but it is complaining that there is no nuspec or project file specified.
I have a "nuget.targets" file and the code compiles fine outside of teamcity , so I think it must be a setting I am missing, and not a file I actually need to add but maybe I do need to add a nuspec or project file? Assuming I do, how would I go about doing that?
[Exec] C:\TeamCity\buildAgent\work\61cf1fbc18b86c6f\.nuget\NuGet.targets
(109, 9): Please specify a nuspec or project file to use.
I am completely new to Teamcity (~3hrs); how do I resolve this problem?
If a build fails or behaves differntly in TeamCity than locally, then it is recommended to run the build in the working folder on agent machine under the same user that the agent is running. Find more details here.

How to create web deployment alone package using TFS

I just need to create Web Deployement package using TFS build and don't want to deploy it automatically in IIS.
I have added the below two parameters in Build Definition - > MSBuild Arguments
/p:CreatePackageOnPublish=true /p:DeployOnBuild=true
The probelm is I am not getting the ZIP file in drop location and getting the below error.
C:\Program
Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
(1657): The "MapUriToIisWebServer" task failed unexpectedly.
System.Runtime.InteropServices.COMException (0x80005000): Unknown
error (0x80005000) at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind() at
System.DirectoryServices.DirectoryEntry.get_IsContainer() at
System.DirectoryServices.DirectoryEntries.CheckIsContainer() at
System.DirectoryServices.DirectoryEntries.Find(String name, String
schemaClassName) at
Microsoft.Web.Publishing.Tasks.MapUriToIisWebServer.get_IisMajorVersion()
at Microsoft.Web.Publishing.Tasks.MapUriToIisWebServer.Execute() at
Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at
Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost
taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost
taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask,
Boolean& taskResult)
What could be the issue?
Now I am getting different error
error : Web deployment task failed.(Object of type 'manifest' and path 'e:\TFS\Dev\ApplicationName\Binaries\Release_PublishedWebsites\ApplicationName_Package\ApplicationName.SourceManifest.xml' cannot be created.)
error : Object of type 'manifest' and path 'e:\TFS\Dev\ApplicationName\Binaries\Release_PublishedWebsites\ApplicationName_Package\ApplicationName.SourceManifest.xml' cannot be created.
error : One or more entries in the manifest 'sitemanifest' are not valid.
error : Application '/ApplicationName' does not exist in site 'Default Web Site'.
I believe you just need to add the 'Package' target to your build for the web project.
/t:Build;Package
I've been using that target in my tfs build to generate the _PublishedWebsite folder with the package zip for a while now with success.
EDIT: Explanation of Package target
If you look at your csproj file for your web application as an XML file, you'll see that it includes the following
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
This includes a bunch of web targets into your build process. Crack this file open and at the bottom you'll see that it in turn includes
<Import Project="..\Web\Microsoft.Web.Publishing.targets" Condition="Exists('..\Web\Microsoft.Web.Publishing.targets')" />
This file contains the definition of the Web Deployment process for MSBuild. You'll see that it declares a variable to denote the "target" to invoke on a Deploy as being "Package"
<DeployDefaultTarget Condition="'$(DeployDefaultTarget)'==''">Package</DeployDefaultTarget>
If you read through this file further it will give you an idea of how Packaging and Deployment work under the covers and what the set of properties and targets are you can manipulate to customize your build.
Long story short though, if you call
msbuild yourwebapplication.csproj /t:Package /p:Configuration=Release
It should build you the web deployment package for the Release configuration of your app.
I had the same issue and the only thing that resolved it was this:
Open your IIS Management console
Go to your Default Web Site
Add new Application named 'ApplicationName'
Run msbuild again. It will work.
Possible duplicate of MSBuild DeployOnBuild=true not publishing
I had the same problem with Atlassian Bamboo, and this fixed it for me: From a machine with Visual Studio copy the contents of "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web" to the TFS Build server.

Teambuild not copying XAP fiesl to _PublishedWebsites

I have a TFS build for sivelright and it copies all the files in the web project to _PublishedWebsites, except the xap file. Error is
Web.csproj error MSB3021: Unable to copy file "Some.xap" to "c:\somewhere\Some.xap" Could not find file "Some.xap".
What it is trying to do, from where it is trying to copy and why it is failing?
Make sure your projects are built in the right order in your TFS Build Definition (Build Definition, Process, Required, Project to Build).