VSTest step in Azure Devops not copying AutoMapper.dll´s - tfs

I am building a solution which has two referenced projects. One of the referenced projects is a test project. The test project has nuget´s and one of the nuget´s includes the automapper nuget as dependency. All the dlls are included in the test project and the automapper.dll and automapper.Net4 are set to copy local. When building it fails with the error:
System.IO.FileNotFoundException: Could not load file or assembly 'AutoMapper, Version=3.3.1.0, Culture=neutral,
If I look into the build server directory I can see that the automapper is missing. If I build the test project locally the automapper dll´s are copied to the output directory.
Any idea why the build server is not copying the automapper files?

VSTest step in Azure Devops not copying AutoMapper.dll´s
According to your description, you may not add the nuget restore task before you build your project, if yes, please try to add a nuget installer and nuget restore from Azure DevOps marketplace to your build pipeline:
If you have already added those two tasks, check the build log of those two tasks.
Hope this helps.

Related

.testsettings deployment section gets ignored in TFS build

I have a solution with bunch of C# projects with bunch of tests. Some of these tests require few native dlls (provided by related nuget packages). To address this .testsettings file was created that is copying dlls (that nuget coped to $(OutDir)) to test directory before running tests.
All this works fine on local machine, but when executed under TFS Build 'deployment' section of .testsettings file (or maybe entire file) gets ignored -- these dlls never materialize in test directory (nor there are any entries in the logs about them). .testsettings file is mentioned in related section of TFS build configuration.
Any ideas what could be wrong? (MSVC 2015, TFS 2013)
For TFS 2013, it only has XAML build. For XAML build, the testsetting file couldn't copy the assemblies from Nuget package $(OutDir) to the C:\Builds\...\builddefinition\...\TestSetting(tst)\...\Out folder before tests run.
I suggest that you could upgrade your TFS to TFS 2015 or upper version to use VNext build. And I have already tested that in Vnext build, it works. This is my build definition example: just add 3 steps.
Have you try to see if they are installed on your TFS server?
Did you check on GAC of the TFS server if they are registered?
Bellow is an explanation of how I deal with my dependencies, hope it helps.
This is my HMO about this topic. Must of the time I avoid to give the responsibility to the TFS to restore the NuGet packages in a separate folder.
How I do that?
1- I create a separate folder at the level of my project. (Common)
If you see on the bottom there is a Nuget.config file. Bellow is the configuration it has
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="$\..\Common\Packages" />
</config>
</configuration>
Now all my Packages are hosted inside Common folder. Now, place all you extra dlls there in a separate folder if you need. If you depend on native dlls that are hosted on the GAC, then you should take a look on the TFS Server if those are installed there.
With that said, I put all my project reference pointing to my Common folder, even my Nuget Repository is getting the files from that location also.
The advantage:
you centralize all your dlls(remember if you depend on a Native dlls, you should install on the TFS the version of the Framework you need in order to run the MSBuild correctly)
all projects point to the same dependencies
you just mantain the Common folder.
Once you check-in a package inside the Common folder, you are guaranteeing that the dependency is also hosted on the TFS, and when the MSBuild runs it can find them.

TFS Build: How to get EXE file deployed to website

I have a TFS Build Definition that builds/deploys a web project to our internal IIS server. That works fine. However, I would also like to build/deploy a WinForms app (.exe) to the same web site.
I did add the WinForms solution to the Build Definition. TFS builds the .exe and copies it to the drops folder. But it's not in the _PublishedWebsites folder.
I've been manually copying the file over to the web site. Is there a way to automate this?
Thanks in advance!
In XAML build, you can check in your script, and specify a post-build script path in your XAML build definition. This script gathers some of the typical binary types from the typical locations and copies them to the folder from which TFBuild copies and drops to your staging location. Check more information about Run a script in your XAML build process at website: https://msdn.microsoft.com/library/dn376353%28v=vs.120%29.aspx
If you upgrade to TFS 2015, in the new build system, you can simply add a PublishBuildArtifacts task in your build definition. About how to use this task, check: https://www.visualstudio.com/en-us/docs/build/steps/utility/publish-build-artifacts

How do I deploy an Azure WebJob alongside a .NET Core Web App via Git?

I thought this would be a pretty straightforward task and there is quite a bit of documentation out there but I've had zero luck with any of it and am assuming that it is pretty much all out of date.
I have .NET Core MVC 6 Web App that I've been developing for a while and need to set up a WebJob for it on Azure. I want to deploy this alongside the app using the continuous deployment system Azure provides that the app is already using. According to Kudu docs it's possible:
https://github.com/projectkudu/kudu/wiki/Web-Jobs#deploying-net-console-webjobs-alongside-an-aspnet-application
Which states:
This works both when deploying directly from Visual Studio
(WebDeploy), or via git.
It references this link (https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-deploy-webjobs/), which I've been attempting to follow with no success.
I have the latest version of Visual Studio 2015, .NET Core 1.0.0 & Tools and the Azure SDK.
First thing that becomes apparent is that I do not have the scaffolding options as shown in the screenshots on the Azure docs and after failing to find any missing dependencies I resorted to trying to set it up manually as described.
Even after putting the required files in the locations specified (webjobs-list.json and webjob-publish-settings.json) and configuring them for my project, and adding Microsoft.Web.WebJobs.Publish to the WebJob project, Kudu does not find the WebJob via the continuous deployment system.
I've tried several approaches and variations based on the documentation I've found out there but I just can't get it working and all other SO questions are year(s) old.
Does anyone know what I'm doing wrong? Is this even still possible with the latest version of .NET Core MVC?
WebJobs' files are stored under the 'App_Data/jobs/continuous' or 'App_Data/jobs/triggered' folders, so one way I could use to deploy both Web App and WebJob is manually copying all WebJobs' files needed to these folders during build time. I think this will fit while VS tooling is being updated.
My solution is a little different from yours since I'm using Visual Studio Team Services to build and release my app to Azure, but the concept is the same. You can use a post build event in Visual Studio to run a script that copies these files to the jobs' folder.
Below are the steps I've configured in VSTS build definition:
Command Line task:
Tool: dotnet
Arguments: restore
Visual Studio Build task:
Solution: **\MyApp.sln
Platform: $(BuildPlatform)
Configuration: $(BuildConfiguration)
Visual Studio Version: Visual Studio 2015
Command Line task:
Tool: dotnet
Arguments: publish -c $(BuildConfiguration)
Command Line task:
Tool: dotnet
Arguments: publish -c $(BuildConfiguration) $(Build.SourcesDirectory)\src\MyApp.Jobs\project.json
Copy Files task (this is the trick):
Source folder: src/MyApp.Jobs/bin/$(BuildConfiguration)/netcoreapp1.0/publish/
Contents: **
Target folder: src/MyApp.Web/bin/$(BuildConfiguration)/netcoreapp1.0/publish/App_Data/jobs/triggered/MyJobName/
Archive Files task:
Root folder (or file) to archive: src/MyApp.Web/bin/$(BuildConfiguration)/netcoreapp1.0/publish/
Prefix root folder name to archive path: unchecked
Archive type: zip
Archive file to create: website.zip
Replace existing archive: checked
Copy Files task:
Source folder:
Contents: **/*.zip
Target folder: $(Build.ArtifactStagingDirectory)
Publish Build Artifacts task:
Path do publish: $(Build.ArtifactStagingDirectory)
Artifact Name: drop
Artifact type: Server

Linked file in WCF RIA service does not build in TFS Build server

I've just setup a TFS (2012) server and now I'm trying to build the complete code (written in .NET 4.0 in VS 2010) via the TFS Build server. But in my solutions I have also a WCF RIA project which contains linked files because they are used somewhere else also and there is no possibility to add a reference to a general .NET binary in WCF/Silverlight.
Everything builds without any problem on my development machine but when I check it all in, create a standard build definition and run that build definition I get the following problem. The linked files have usings (UsingNamespace for example) to other projects that are also build by us and build before the WCF/Silverlight but the following error pops up while building through TFS Build server:
The type or namespace 'UsingNamespace' could not be found (are you
missing a using directive or an assembly reference?)'
Is there any solution for this problem that I looked over?
EDIT 1
Just tried to set the Copy to Output Directory propertie of the linked files to Copy Always but this still gives me the same error as I was expecting. The problem is that the linked file is placed somewhere that it can use the usings but the WCF RIA service cannot access/find that using.
EDIT 2
Just tried out my local test TFS where I can do what I want and there I made a build definition with just the solutions needed to make that the project with the linked files builds. This worked without any problem. Then I tried the same on our TFS server with a new build definition that has the same solutions as on my test TFS and here it did not work. The only difference that I know for sure is that my test TFS is TFS 2012 Update 1 and that my production TFS does not have the update 1 yet. I'll try to install it next week.
EDIT 3
I've just updated our production TFS to Update 1 but it is still not working with my temporary build definition which only contains the projects that are needed to build the silverlight application with the linked files. The 2 workspaces are the same on both server and the projects to build are also the same.
You need to specify the workspace information in the Build Definition for the build to use. The workspaces are what the build process copies from source control to the build server. If you don't have everything in the build server's workspace, it can't build properly.
The Source Control Folder in the workspace tab is the location of the files you need from TFS. The Build Agent Folder is a relative path from the build server's pre-defined base location. You'll usually use $(SourceDir)\Folder to specify the "Folder" that your build process needs.
This sounds like an $(Outdir) problem. A build definition in TFS automatically overrides the Bin folder. All Binaries are redirected to the bin folder upon compile. Sounds to me that you are using a mixture of project references and file references. The file references are probably what is causing your build failures.
Example if you compile in the same build the following solutions
Solution1.sln (TFS Build Pass)
project1.csproj
project2.csproj (references project 1)
Solution2.sln (TFS Build Failure)
project3.csproj (references binary output of project 1)
Expectations from TFS out of the box without customizing your workflow is that this simple build will fail. The reason is that in your development box all projects produce output to one destination while in a tfs build your projects will build to $(Outdir).
Some Things to try
Simple (best practice in my view)
Create 1 solution and use project references instead of file references.
Complex
Build using MSBuild project files
Modify your windows workflow to not override the $(Outdir)
Copy the binaries after a build is complete.
Best practice on Automating Builds
Build from command line
Build from cmd a NON vs2010 command line.
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe FullpathtoSolutionFile.sln
Cheers!
Apparently there was just missing the WCF RIA services V1.0 SP2 on the TFS server. If that was installed the problem was solved.

Using Octopack on a TFS build with a website + windows service

I have a website, a windows service, and some shared class libraries in a single Visual Studio solution. I use Octopack on both the website and windows service, and on my machine these builds work as expected.
When using the TFS Build Server, the website nuget package is generated as expected, but the windows service nuget package contains all files from the website, as well as the service. E.g. it includes the _PublishedWebsites folder as well.
This is because TFS uses a single location to build projects.
What is the best way around this?
I know this question has since been closed, but I cam across this issue and solved it in a different way.
My solution is compromised of a number of websites and windows services and had the same issue of the OctoPack created nuget packages including all the solution assemblies from the 'pooled' output folder when building with Team Build. The reason the nuget packages get all the assemblies is OctoPack uses the outdir msbuild argument as the location to include assemblies from.
The way I got around it was to use the msbuild argument GenerateProjectSpecificOutputFolder=true. This instructs Team build to create a folder for each project in your output folder in the same way Visual Studio uses the bin folders under each project when building locally.
My build definition msbuild arguments looks like:
/p:GenerateProjectSpecificOutputFolder=true;RunOctoPack=true;OctoPackPublishPackageToFileShare=\\<NugetServer>
I currently just push the packages onto a shared folder but the OctoPackPublishPackageToHttp and OctoPackPublishApiKey parameters can also be used.
The benefit of this solution over the one above is you don't need to specify the files to include the nuget package.
Hope this helps someone.
I ended up using this nuget package to ensure the console app built to a seperate directory on the TFS server.
https://nuget.org/packages/PublishedApplications/2.1.0.0
I then had to specify in the nuspec file, which files should be included for the console app. e.g
This works and I can now deploy using Octopus deploy.
The downside of this apporach is that the PublishedApplications build only works on the TFS build server, so I can't build the project locally in release mode. Still looking on how to overcome this.

Resources