Compile from inside Sublime using MSBuild package - msbuild

I installed the sublime MSBuild package. I have a sublime project setup with the directory structure that includes the solution and visual studio projects.
rootdir/src/codehere
rootdir/.build/vcproj/projectshere
I try to build the project from a source file in the src directory by hitting ctr+b. I get this error in the output window.
rootdir\src\foo.cpp(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
I didn't see any documentation in the MSBuild package for pointing it to the specific visual studio solution.

The documentation is clear on this:
Build system: Execute the currently loaded MSBuild script and capture the results in the output pane
In other words, open the project or soltuion you want to build, then hit Ctrl-b
edit looked into this a bit and the main reason it is done the way it is is just because it makes the most sense: in ST, just like in most other text editors, there's always one 'active' file on which commands are invoked.
That being said there might be a solution for you by creating a cutsom Sublime 'build system'. Combined info from SublimeMsBuild itself and from the Sublime build system syntax pages: select Tools->Build System->New Build System and paste the following into the file:
{
"shell_cmd" : "msbuild",
"working_dir" : "$project_path",
"windows":
{
"path": "%PATH%;%WINDIR%\\Microsoft.NET\\Framework\\v4.0.30319;%WINDIR%\\Microsoft.NET\\Framework\\v3.5;%WINDIR%\\Microsoft.NET\\Framework\\v2.0.50727"
},
}
and then save it appropriately. This will give you a new build system which can be selected from the Tools->Build System menu and when executed will invoke msbuild in the directory of the current Sublime project's path. Now invokation of msbuild doesn't depend on the current file anymore, instead on the current project. So all you have to do is save a sublime project into the directory where you also have your msbuild solution/project, open the project and then hit Ctrl-b whenever you want.

Related

Wix - building files to subdirectories

I am new to WiX and am trying to get my install project to build certain files to a subdirectory of the build output path. For example, if my build output path is: bin\Debug, I would like certain files to be added to a subfolder here: bin\Debug\Images.
Is this possible please?
It looks like you are using a WiX project template with Visual Studio, MSBuild and/or SharpDevelop. If so, you have several options:
Use XCOPY in the Post Build Event.
flexible
somewhat easy to find in your project (on one of the project designer tabs)
not integrated well with the build system
Add the folder and files to your project folder, include them in your project and set the Copy to Output Directory on each file. Note: you can't set that property on a folder. The copying will preserve the folder structure but you have set the property on each file you want copied.
inflexible
very easy to find in your project (solution explorer and properties window)
Open the project file in a text editor and add MSBuild tasks such as Copy to the AfterBuild or other target. Note: To use VS to edit the project file, right click, select Unload Project, then right click and select Edit.
flexible
hard to find in your project (XML in the project file)
uses the build system
In the last case, I sometimes put a REM comment in the Post Build event to clue people into the fact that the project file has been customized.

IAR Embedded Workbench and Custom Build

I have a project in IAR Embedded Workbench that works fine. In this project there is a source file (webpages.c) that is automatically created by another tool. This tool creates the file webpages.c starting from the files located in the specified folder webpages (so one file is generated starting from a set of files).
I want to configure the project in IAR in such a way, before the building process, the tool is automatically run if a file in the webpages folder is changed since the last build.
I configured a pre-build step and it really works with a Rebuild All. But if I change just a file in the webpages folder and issue a Make command, IDE thinks the project is up-to-date and doesn't start building.
Any solution?
Can't you add them as files to your project under a separate group ?
Then, right-click the options for the group, select custom build, check "override inherited settings" and fill in the commands for the custom build step.

How do I make a build system for Sublime Text 2 to build msbuild?

I would like to use Sublime Text 2 to build my Visual Studio 2010 solutions.
So far I have this:
Menu item Tools > Build System > New Build System...
{
"cmd": ["c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"]
}
I get this error:
MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution file.
I'm wondering how I specify a project folder directory in the build file.
I got it to work by modifying the build system file C:\Users\dave\AppData\Roaming\Sublime Text 2\Packages\User\msbuild.sublime-build like this:
{
"cmd": ["c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"],
"working_dir": "${project_path:${folder:${file_path}}}"
}
I looked at an existing build configuration that shipped with Sublime to figure it out:
C:\Users\myUser\AppData\Roaming\Sublime Text
2\Packages\Makefile\Make.sublime-build
There is now a full MSBuild package for Sublime Text 2 that includes syntax highlighting and completion in addition to build system integration. You can install it using Package Control or directly from https://github.com/tillig/SublimeMSBuild.
Here is reference to all features of Sublime's Build System.
The error message is because you did not specify what you wanted to build. See the MSBuild Command Line Reference. At the very least you need to specify a project file:
MSBuild MySolution.sln
MSBuild MyProject.csproj
MSBUild MyMSBuildScript.proj

teamcity building project Failed to start MSBuild.exe. Illegal characters in path

I am trying to build a project within teamcity. It will do the checkout of TFS and the files are locally on the build server. If I manually run the build command on the server it works:
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\msbuild.exe C:\TeamCity\buildAgent\work\3446a5bd436eea87\Dev\Dev\project\myproj\myproj.csproj /t:build
Within Teamcity I have a Build step of MSBuild:
the build fie path is: Dev\Dev\project\myproj\myproj.csproj"
working directory left blank
mbuild version: microsoft .net framework 4.0
msbuild toolsversion: 4.0
run platform: X86
targets: I have tried build "build" and left blank
command line params left blank
if I create a command line build task and run the above command line it works. I am not sure what differences there are between the command line and msbuild task within teammcity.
EDIT
I have tried a few variations on the working directory:
The output path in project is set to ..\Build\Tools\myproj\
So I have set the working directory in teamcity to: Dev\Dev\project\Build\Tools\myproj\
This didn't help.
Here is the exact output from teamcity:
Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\TeamCity\buildAgent\work\3446a5bd436eea87\Dev\Dev\project\Build\Tools\myproj /msbuildPath:C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
in directory: C:\TeamCity\buildAgent\work\3446a5bd436eea87\Dev\Dev\project\Build\Tools\myproj
Failed to start MSBuild.exe. Illegal characters in path.
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.IsPathRooted(String path)
at JetBrains.TeamCity.Utils.FileUtil.MakeFullPath(String path, String workDir) in c:\BuildAgent\work\c2314fd21f15dc97\src\Utils\src\FileUtil.cs:line 48
at JetBrains.BuildServer.MSBuildBootstrap.RunArgs.get_ProjectFile() in c:\BuildAgent\work\c2314fd21f15dc97\src\MSBuildBootstrap\src\RunArgs.cs:line 156
at JetBrains.BuildServer.MSBuildBootstrap.Impl.MSBuildBootstrapFactory.Create(IClientRunArgs args) in c:\BuildAgent\work\c2314fd21f15dc97\src\MSBuildBootstrap.Core\src\Impl\MSBuildBootstrapFact ory.cs:line 29
at JetBrains.BuildServer.MSBuildBootstrap.Program.Run(String[] _args) in c:\BuildAgent\work\c2314fd21f15dc97\src\MSBuildBootstrap\src\Program.cs:line 67
Try editing the build configuration and remove the quotes from the Build file path option.
If you have:
"Dev\Dev\project\myproj\myproj.csproj"
Just let:
Dev\Dev\project\myproj\myproj.csproj
I hope this help.
In TeamCity, when you are using parameters for your path, or a portion of the path, it is easy to paste in a folder and not notice that it has a New Line or Carriage Return on the end (as I found from painful experience). It could show up in TeamCity as the value for a parameter:
\Folder1\NewlyPastedInFolder
\ExistingFolder\BuildScripts
What looks like a word-wrapped value is actually a parameter with a carriage return in the middle. Check it by editing it, and see if you can delete the character to make it into a single-line value.
This questions seems very similar:
What's the illegal character in this string ? I'm getting MSBUILD : error MSB3095
In addition to this question, take a look at:
What is a dll.refresh file in ASP.Net?
On this question, this answer is of interest:
In an ASP.NET project, adding a file-based reference will add a
.refresh file in the Bin folder. When the project is under source
control, this file is then added to source control. *.dll.refresh
files that litter the bin directory. Every time you add an external
reference, you'll find a dll.refresh file right next to it. These
dll.refresh files are an exception to the rule, and they should go
into source control. Its the only way your web project will know where
its references live.
If you don't have this in source control, it could explain the problem you are seeing. It sounds like the error message is potentially misleading and this is related to a reference not being resolved on the build machine.
With regards to why it works from the command line, is it possible that when you are building from TeamCity it is cleaning the output directory before building? If when you run from the command line binaries have already been output from the partially failed build which are referenced as file references, this would succeed.
To identify if this is the case - if you do a completely clean checkout and then run the MSBuild step from the command line, does it still succeed?
I ran into this error message from TeamCity and it turned out that a space in the solution file was causing it (the solution file referenced in the Visual Studio Build Steps had double quotes around it and that didn't seem to help.) Renamed the solution file without the space and that solved the problem.

Generating an MSBUILD project file from a visual studio solution file and project files

I know that I can pass MSBuild a VS solution file (.sln) and it will build the solution but somewhere in the back of my mind, I remember using a MSBuild command line switch that would take a solution file (and it's referenced project files) and generate a single MSBuild project file from them. However, I now can't find this switch!
Was this all a dream?
I see the /preprocess switch (short form /pp) but I don't think that this was it as this will include all of the imported files (including Microsoft.*.targets) and besides I can't seem to get this switch to work. I when I try the following command line, MSbuild generates the *.out file but its empty!
msbuild /target:rebuild /generate MSBuildCopyTargets.sln
The easiest way to do this is to run MSBuild from the command line, with an environment variable set:
Set MSBuildEmitSolution=1
The output will be in the format SolutionName.metaproj