batch file unreachable script - msbuild

I am new to batch scripting. Can someone help me with the following?
call %comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
set MSBuildEmitSolution=1
msbuild "C:\Users\bleh\Documents\Visual Studio 2010\Projects\BuildApp\BuildApp.sln"
pause
This executes only the first line of the batch file, i.e. sets the VS environment.
Suggestions please.
Cheers!!

Try replacing /k in the first line with /c. The /k switch to cmd.exe causes the command interpreter to run the command and await user input afterwards, whereas /c causes it to exit after running your command.

Related

Argument To Input Into VS12.0 Command Prompt To Open To a Specific Line Number vb.net

I'm looking to write some code to open the visual studio command prompt and move to a specific line number. Here's what I've gotten so far:
Process.Start("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\Shortcuts\Developer Command Prompt for VS2013.lnk", "/K devenv /edit FileLocation /command ""edit.goto LineNumber""")
Command prompt opens up but I've having trouble making an argument. The command:
devenv /edit FileLocation /command "edit.goto LineNumber"
works on the command prompt, but I'm not sure how to input this command into vb.net using process.start()
First of all, don't use shortcuts to locate programs.
You should find Visual Studio's directory, instead, then execute it from there. For example, mine is located in C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE.
For example:
Process.Start("C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe", "/edit ""FileLocation"" /command ""edit.goto LineNumber""")
This way you don't have to rely on the existence of the shortcut.

MSBUILD : error MSB1001: Unknown switch Switch: /Y

I'm using team city to make an automatic deploy and MSBuild won't work...
In the build step the the command line parameters look like this:
ProjectName.deploy.cmd /y /M:https://[WebDeployUrl:8172]/MsDeploy.axd /u:username /p:password –allowUntrusted /A:basic
this works fine from my machine, but the build server fails with the following response:
[MSBuild output] MSBUILD : error MSB1001: Unknown switch.
[MSBuild output] Switch: /Y
Anyone has an idea about this?
This is a very old question, and the asker likely sorted out their issue long ago, but here goes anyways:
MSBuild tasks in TeamCity require a commandline that pertain to MSBuild.exe specifically, IIRC.
That is, TeamCity is executing MSBuild.exe with the parameters you've given it like so:
msbuild.exe ProjectName.deploy.cmd /y /M:https://[WebDeployURL]:8172]/MsDeploy.axd /u:username /p:password -allowUntrusted /A:basic
Of course, MSbuild has no idea what those switches are, nor would it be able to process 'ProjectName.deploy.cmd' as an MSBuild file.

Writing log file in temp folder by IExpress

I'm using IExpress to generate .exe installer.
I want to make it generate log file into temp folder like this.
msiexec /i MyPackage.msi" /l*v "%temp%\MyPackge.log"
but after a bit of research I found that IExpress use command.com not cmd.exe so that it doesn't understand %temp%
So, I try changing it to
cmd.exe /c msiexec /i MyPackage.msi" /l*v "%temp%\MyPackge.log"
it seems work but there is a command prompt appears while installing which is not nice at all.
Anyway to fix this ?
you can choose to install /q quiet with no UI and /norestart options
msiexec command line options http://msdn.microsoft.com/en-us/library/windows/desktop/aa367988%28v=vs.85%29.aspx
You can hide the cmd.exe window by changing the Show window option to Hidden in the IExpress Wizard. In the .sed file, this would be:
ShowInstallProgramWindow=1
I end up with this.
msiexec /i MyPackage.msi" /l*v "..\MyPackge.log"
because the .msi has been extracted to %temp%\MyProduct, that's why I can use "..\MyPackage.log"

Using Code Contracts in library code built with MSBuild

I've started using Code Contracts in all new code I'm writing, such as in a framework library I'm building to help bootstrap IoC, O/RM, etc., in an ASP.NET MVC application. I've written a simple build script for this framework library that looks like the following:
#echo off
echo.
echo Cleaning build output (removing 'obj' and 'bin' folders)...
for /f "tokens=*" %%G in ('dir /b /ad /s bin') do rmdir /s /q "%%G"
for /f "tokens=*" %%G in ('dir /b /ad /s obj') do rmdir /s /q "%%G"
rmdir /s /q build
echo.
echo Starting the build...
call "%VS100COMNTOOLS%\vsvars32.bat"
msbuild Integration.build /target:Build
echo.
echo Done!
pause
This doesn't work. What I end up with in my build folder if I run this is, for whatever reason, assemblies that aren't fully rewritten by ccrewrite alongside .pdb.original, .rewritten and .csproj.FileListAbsolute.txt files that litter the output directory.
What does work is first building the solution in Visual Studio 2010, commenting out line 3 through 7 in the batch file and running it again. I then end up with properly rewritten assemblies and no .pdb.original nor .rewritten files.
What I've deduced from this is that Visual Studio 2010 somehow triggers the Code Contract rewriter properly so the resulting assemblies from the Visual Studio 2010 build is re-used by the command-line MSBuild call, so what my batch script basically does is just copying files to the build directory. Rather useless, in other words.
I've read this, but Jon's problem seems different from mine since ccrewrite is obviously doing something, but it's just not completing the rewriting for whatever reason. The Integration.build file builds the correct configuration (that has Code Contracts enabled in the .csproj files) and everything else looks right, it just doesn't work properly.
So, I'm wondering: How do I run MSBuild the way Visual Studio 2010 is where ccrewrite does what it's supposed to and doesn't litter my output directory with .rewritten and .pdb.original files? Does anyone have a perfect example of how an MSBuild file doing proper Code Contracts rewriting looks like?
The answer is in the script. All Visual Studio is ever going to do is run MSBuild tasks that will invoke others. One thing you can do is go to Tools|Options|Build... and turn on logging so you can see in detail which bit is doing what to generate the artifacts.
How would one do such a complex and involved thing? Read a guide to MSBuild such as Hashimi p1 and Part 2.
Then dig into the source for the build in e.g.:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets
The best way to get there is to open your .csproj and look what it includes and go via that (the .CSharp.targets is the first one - the one I cited comes further down the stack).
(That and wait for someone to pop in with an actual answer!)
I've played a little with Code Contract's static analysis and it is pretty cool.
Now trying to set up TeamCity build ...
Here is msbuild integration info from Microsoft Research (see page 44)

SolutionDir set to *Undefined* in post-build xcopy event

I have a project that has a post-build event that xcopies a DLLs to a certain directory:
xcopy "$(TargetDir)$(TargetName).dll" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y
xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)..\UdpLocationService\bin\Plugins\" /d /y
However, I have CruiseControl.NET set up as a build server and MSBuild is failing on building that project due to this xcopy post-build event:
MSB3073: The command "xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.dll" "*Undefined*..\UdpLocationService\bin\Plugins\" /d /y xcopy "C:\Build\Services\Windows\VehicleServer\Plugins\Payload\bin\Debug\Payload.pdb" "*Undefined*..\UdpLocationService\bin\Plugins\" /d /y" exited with code 4. in Microsoft.Common.targets(3397, 13)
Any suggestions to get this fixed?
I just ran into the same problem with TeamCity.
The issue here is the $(SolutionDir) property in your build file. You haven't defined it in your call to MsBuild (this is why you see the word undefined in your output).
Call msbuild with the property set, like this:
msbuild myproject.csproj /property:SolutionDir="solution directory"\
Where "solution directory" is the directory containing your solution file. Note the trailing slash, you'll need that to make sure the path is correctly formed.
I fixed this for problems with the Microsoft.SqlServer.Compact nuget package (which adds a similar post-build script), by adding:
<SolutionDir Condition="'$(SolutionDir)'=='' or '$(SolutionDir)'=='*Undefined*'">..\</SolutionDir>
right above the <PostBuildEvent>. You'll want to adjust the relative path to match your project layout.
Follow these steps:
Unload your project file (e.g. *.csproj)
Open your project file for editing
Find the AfterBuild target
Separate out the two invocations of XCopy into two distinct Exec tasks
Save your changes and Reload your project file