How to specify root folder for Package target? - msbuild

I publish my web application using msbuild by calling following command:
msbuild myweb.csproj /T:Package /P:PackageLocation=obj\Output\myweb.zip
The content of zip file has always deep folder structure containing full path from drive root to the project folder. Is there any way how to make it more flat? I would like to have a project folder like root in zip.

You can use _PackageTempDir instead of PackageLocation for IIS-like flat structure, but if you want to keep the .zip and .cmd with manifests then no, you can't really get away from absolute paths without rewriting Microsoft.Web.Publishing.targets or a custom task due to the way the var is used.
<_PackageTempDir>$(PackageTempRootDir)\PackageTmp</_PackageTempDir>
<_PackageTempDirFullPath>$([System.IO.Path]::GetFullPath($(_PackageTempDir))</_PackageTempDirFullPath>
<_MSDeployDirPath Include="$(_PackageTempDir)" />
<_MSDeployDirPath_FullPath>#(_MSDeployDirPath->'%(FullPath)')</_MSDeployDirPath_FullPath>
You can however trick msbuild and flatten it a little bit by hiding the absolute path with a local share, something like this:
net share foo=D:\Temp
msbuild WebApplication1.csproj /t:Package /p:PackageTempRootDir=\\localhost\foo
That'll change your deep local path to something like obj\Debug\Package\WebApplication1.zip\Content\_S_Slocalhost_Sfoo\PackageTmp

Related

Can CLion project files be stored in a specified folder by default?

I've been using CLion for a little while now, and I quite like it, except that it stores it's prject files by default in my CMake project. I am wondering if I can set a default place it stores it's project files(like compiled executables) in specific directory, per project.(So not one big folder that might interfere with other projects). The reason I want to do that is because I don't like having it in my git project(yes, I know about .gitignore) Anyone know how to do that?
Thanks!
To use a different folder for CLion building
In the CLion menu:
Build,Execution,Deployment -> Cmake -> Generation Path
Change the value to the folder path you want.
To include source code from a different folder out of current
In your CMakeLists.txt, add subdirectory like following:
add_subdirectory(<PATH_OF_YOUR_ANOTHER_CMAKE_PROJECT>)
Be aware PATH_OF_YOUR_ANOTHER_CMAKE_PROJECT can be anywhere on your computer, which does not have to be in your current project folder or one of the sub-folders.

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.

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

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.

MSBuild isn't resolving the correct path from an imported file

I'm having an issue with MSBuild 4.0 not resolving a path correctly in one of my imported MSBuild files. ProjectOne.csproj at the very beginning of the file imports GenericProject.proj.
GenericProject.proj then goes on to import the ProjectOne.settings file when it needs it via a call structured like:
<Import Project="$(MSBuildProjectName).settings" />
I had assumed that when the import was resolved it would have a path of something like:
/Project Root/Src/ProjectOne/ProjectOne.settings
But when running the ProjectOne.csproj through MSBuild I got a path of:
/Project Root/Targets/ProjectOne.settings
This doesn't make sense because considering all paths are suppose to be relative of the master project, in this case ProjectOne.csproj.
So I'm wondering if someone knows why this is happening?
Folder Structure:
Project Root
Src
ProjectOne
ProjectOne.csproj
ProjectOne.settings
Targets
GenericProject.proj
I don't think this matters, but just in case I'm running windows 7 x64
Edit: (1:45-11/7/2010) I was able to solve the problem by adding the $(MSBuildProjectDirectory) tag in front of $(MSBuildProjectName) but I still don't know why it wasn't resolving correctly in the first place.
all paths are suppose [sic] to be relative of the master project
Where did you get that idea?
<Import> elements are relative to the importing file.

How can I filter which files are included in a workspace using MSBuild?

It seems that MsBuild creates a folder called, "BuildType" on the build server and this folder is where the .proj file is copied. In source control I have several files that are in the same folder as the build project file. I have a workspace mapped to this location.
I would like to be able to specify explicitly which files from this workspace location should be copied to the build machine. Is this possible?
Thanks!
You cannot do this on file level but if you organize your build type folder with subfolders you can cloak the folders that you want to exclude.