How do I set up the MSBuild script to use the outdirectory's set in the csproj files while building the entire solution? - msbuild

I'm not sure how I can get the MSBuild script to use the outputpath, outputdirectory values from the CSproj files. I've seen examples where I set the outputpath in the MSscript but that dumps the all the output in one big folder. I want the individual projects to have their own output paths and MSbuild to build the solution in such a way that the output for the projects and created in the corresponding output directories. Thanks.

There is not an easy way. One option is to extend MSBuild and have it copy the output from each project to a common folder.
If you look at the Microsoft.Common.Targets file in the c:\Windows\Microsoft.Net\Framework\v4.*\ you can see how it does load a custom targets file at both the beginning and end of that folder. If you add a Custom.After.Microsoft.Common.Targets to the C:\Program Files (x86)\MSBuild\v4\ folder you can have it load a file say $(SolutionDir)\Solution.targets. This will allow you to extend each solution differently and you can add any custom actions you want inside every solution that applies to every project. I use this and it works great.

Thanks for your answers guys. I found a way to run the solution without giving a specific output folder. I had to fix the output folder path to /bin in the csprojs and then running MSbuild with the solution was able to pick up those paths from the csprojs and build the output into those folders.

Related

How to properly specify DocumentationFile in MsBuild 15 .csproj with multitargeting

I am using the latest preview of MsBuild 15 and I have a multitarget project file targeting both net40 and netstandard1.6.
I am struggling with specifying <DocumentationFile> correctly.
For any path I would specify, the resultant xml file after the build will be both in that path and two target output directories.
For instance, if I specify
<DocumentationFile>doc.xml</DocumentationFile>
Then the xml file will be generated both in my project dir and bin\net40 and bin\netstandard1.6.
I need those xml documentation files only in my bin\net40 and bin\netstandard1.6 directories. How can I achieve that?
Also, with the current behavior, it is not clear which documentation file is copied to my project dir, because those xml documents can differ for two targets.
In earlier project versions I used to specify documentation xml path separately for Debug and Release build configurations with paths like bin\Debug\doc.xml, but with the newest MsBuild 15 it is possible to do multitargeting and the number of such paths double if I specify the dir for all possible combinations of target and build configuration.
Is there any generic good way to specify documentation file path once and get it to the right output places only?
From my testing if you specify
<DocumentationFile>bin\Debug\netstandard1.0\MyProjectName.xml</DocumentationFile>
it will create doc file in each multi-targeted folder so it'll create
netstandard1.0\MyProjectName.xml
net45\MyProjectName.xml
netcoreapp1.0\MyProjectName.xml
netstandard2.0\MyProjectName.xml
etc.

Visual Studio ASP.NET Web API Precompiled files placed in a different folder with TFS

I have an asp.net web api project whose output needs to be packaged in a setup project using wix.
I would like to precompile the site. The problem is that the precompilation process generates variable file names (ie. *.compiled files in particular).
I also would like to build the setup in a TFS build.
It seems that my only option is to generate a .wxs file wihtin the prebuild step of the wix project.
The .wxs files source paths are using $(var._My_Web_Project_.TargetDir). This seems to be translated to a Sources based directory.
I'm using paraffin to do that already and it works perfectly fine when building the solution with visual studio.
When building the solution through a TFS build, the .compiled files are copied to a Binaries folder, whereas all the other related web site files are copied to a Sources based directory.
The build errors are like the following :
The system cannot find the file 'd:\BuildAgents\___basedir___\Binaries\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'.
The file is indeed in the Sources directory.
'd:\BuildAgents\___basedir___\Sources\___web_project_dir\_PublishedWebSites\___site___\bin\textsample.cshtml.c6fb271c.compiled'
I think I somehow need to redefine the aspnet_compiler output or something like this, but can't figure out how to do that.
The msbuild command line arguments are the follwing:
/p:GenerateProjectSpecificOutputFolder=true /p:VisualStudioVersion=14.0 /p:DeployOnBuild=true /p:PublishProfile=local /p:CleanWebProjectOutputDir=False /verbosity:d
EDIT 1: I'm using XAML build.
Any help appreciated.
EDIT 2:
With the new task based build, it works as is (no need to use an additional Copy Files task).
The aspnet_compiler output the .compiled files in the correct folder :
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project\obj\Release\AspnetCompileMerge\Source -c D:\BuildAgents\vNext\_work\1\s\Softs\__Solution__\__Web_Project__\obj\Release\AspnetCompileMerge\TempBuildDir
In the new tasks based build system, it's easy to copy files from a source folder to a target folder with Copy Files task.
Source Folder: Folder that contains the files you want to copy.
Contents: Specify minimatch pattern filters (one on each line) that you want to apply to the list of files to be copied.
Target Folder: Folder where the files will be copied. In most cases you specify this folder using a variable.

MSBuild Package Location

When I run MSBuild with the /t:Package parameter I want to be able to specify where the folder that contains the *.cmd and *.zip files gets output. Specifying _PackageTempDir outputs the entire application without the deploy files (*.cmd and *.zip). Is there any way to specify this in the command line?
UPDATE:
The OutDir param outputs more than I need or want.
I've found that setting /p:DesktopBuildPackageLocation=some\package.zip for MSBuild doesn't work (it works when specified in pubxml though).
However, it turns out that setting /p:PackageFileName=some\package.zip works fine. Furthermore, you can use it along with /p:PublishProfile parameter.
If you set
<DesktopBuildPackageLocation>c:\foo\MyProject.zip</DesktopBuildPackageLocation>
you'll get the .zip file, the .cmd file, and the other related output files in c:\foo.

How do i navigate through folders in code behind?

I need to address a file in my code. this file isn't located in my main project, but in a library project. When i call AppDomain.CurrentDomain.BaseDirectory, i end up in the start project's (let's call it mainproject) debug folder. What i want to to is call appdomain.cd.bd and go up 3 levels, so i leave debug, then bin and then mainproject. Then i would navigate to libraryproject and to folder where file is located.
What i've tried so far is do AD.CD.BD\..\.. or AD.CD.BD/../..
I thought i remembered those, but it's a no go.
Does anyone know how to do this.
Thanks in advance
It is concerning to see you wanting to codify paths based on project build paths. What happens when you release the project and these project directories don't exist.
I would recommend that if there is a file your project needs to execute is from a library project that doesn't get copied across during the build that you use a post build step to copy this file to the same location as your assembly. Alternatively you may be able to set the build action on the file in your project which might get this file to your main project build output directory.
Three levels up would be ../../../ wouldn't it?

Build VC++ project with additional cpp file using MSBuild

I need to build VC++ project (made in VS2008) from command line using MSBuild with additional .cpp file which isn't part of this project (doesn't listed in section of .vcproj file.
Is there are any way to do this? (e.g. just by passing filename to command line input).
Editing .vcproj file by my script is also is a option but I save it for a worst scenario when there are no way to do it just with MSBuild.
I don't think you can point MSBuild at a project file and tell it to build this project and add another file at the same time. I'd either update the .vcproj file to include the file you're trying to add or go for the script-driven editing approach. Actually, I'd probably just change the .vcproj file as I'd think this is the safer approach and less likely to break something.
You can add the file to the project if it's in the same directory.
If it's shared / in another directory you can try adding as a link.
In the Add / Existing Dialog notice the Arrow on the edge of the add button. Try clicking it.