build .net solution from batch file - c#

I have a solution file comprising of 15 projects using a few third party dll references. I want to be able to build the solution from a batch file. What is the best way to do this?
Thanks

Run msbuild - for example:
msbuild MySolution.sln /p:Configuration=Release /p:Platform="Any CPU"

One of the simplest ways is to execute msbuild with the solution file as input:
#echo off
call %windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe path\to\solution.sln
If this is done in a Visual Studio command prompt you can skip the path to msbuild.exe.

One way to get started is to open the project in Visual Studio and select Build | Rebuild Solution. Then go to View | Output. In the output window select "Build" in the Show Options From dropdown. This will display the commands that Visual Studio is using to build the project. You can paste those into a batch file, and read or modify them as desired.
If you want to maintain both Debug and Release versions of your application, then you will want to select the correct configuration and then follow the above steps for each version.

Related

Cannot create .apk file after introducing Crypto Obfuscator into Xamarin.Android project

I have a task of obfuscating my Xamarin Android project (let call it AndrProj) together with libraries it references: two PCL (let's call them PCL1 and PCL2) and Android library (AndrLib). PCL2 and AndrLib also have references to PCL1.
I was inspired by this article and decided to try Crypto Obfuscator For .Net v2015 demo version for my purposes.
I used its 'Visual Studio Project Integration Wizard'. PCL1 was set as 'First project' and AndrProj as 'Last project'. Only default settings were used for the beginning. Now when I build my project everything is perfect. Dll's in \bin\Release folder are obfuscated.
I would be completely happy if I could actually create an .apk file and try it on the Android device. But when I select Build -> Archive for Publishing in Xamarin Studio, after some time I see 'Build FAILED' and
Error occurred while obfuscation: - The assembly 'AndrLib' is
already obfuscated with Crypto Obfuscator. If you have run the Visual Studio Project Integration Wizard on your Visual Studio projects, you cannot obfuscate from the Crypto Obfuscator UI unless you first disable automatic obfuscation for this project from Crypto Obfuscator's 'Project' menu --> 'Enable/Disable Visual
Studio Integration' and Rebuild your solution in Visual Studio to
produce unobfuscated assemblies.
I also tried 'Export Android Package (.apk)' from Visual Studio 2013, but it gives less output and still does not create .apk.
I believe it complains only about AndrLib because it goes first alphabetically among PCL1, PCL2 and AndrLib. And more global problem is that creating .apk forces all assemblies to be obfuscated one more time. Is there any way to skip this second time obfuscation? Or to ignore this kind of problem?
Well, the solutions was pretty simple: I had to use MSBuild.exe directly with target SignAndroidPackage instead of creating .apk from IDE.
Here is an email from technical support regarding the described problem (may be useful for someone):
If your solution fails to build after doing MSBuild Integration, try the following:
Change the build output log verbosity as follows:
Visual Studio Tools menu --> Options --> Projects And Solutions --> Build and Run --> MSBuild Project Build Output Verbosity, set this to Detailed.
Now check the Visual Studio Output window for any hints or more information regarding the cause of the error.
Change the number of threads used by MSBuild to 1 as follows:
Visual Studio Tools menu --> Options --> Project And Solutions --> Build And Run --> Maximum number of parallel threads : set this to 1.
If you get an error message similar to "The assembly 'XYZ' is already obfuscated with Crypto Obfuscator..." when you Run (CTRL+F5) or Debug (F5) your solution, then try doing a Clean ( Visual Studio Build menu --> Clean menu item) and then do the Run (CTRL+F5) or Debug (F5).
Build failure can also occur if you ran the wizard multiple times, each time selecting a different "first" project. This problem usually presents itself via a "file not found" error in the build log/output. To solve this problem, start from clean non-integrated .csproj/.vbproj files (the wizard copies the original non-integrated project files to a .backup_%timestamp% extension before modifying the project files; alternately you can open the .csproj/.vbproj files in a text editor and remove the XML added by the wizard which can be found towards the end of the file). Then run the wizard again specifying the correct first and last projects.
I had problems Archiving and the problem went away after I downgraded Visual Studio 2017 Professional from 15.9.9 to 15.7.6.

how to run an mstest dll from command line

anybody knows how to run unit test dlls built using mstest from the command line, without running VS
considering that on the machine there is .net 4.0 and VS2010 installed
I haven't done it myself, but I'd imagine that using the mstest command line is the way forward... if you've already tried that and had problems, please give more details.
mstest /testcontainer:path\to\tests.dll
EDIT: As noted in comments, you should either do this after putting the right directories on the path, or include the full path to mstest.exe.
Quick Answer :
Examples
You must use the /testcontainer option together with the /category option to select which tests in which categories to run. The following command, for example, is run in the solution folder and runs the tests that are in both the Priority 1 and ShoppingCart categories.:
MSTest /testcontainer: testproject2\bin\debug\testproject2.dll /category:"Priority1&ShoppingCart"
Note
Because the test assembly file resides in a different folder, a relative path is necessary,
If you are using test lists, it is best to use the /testmetadata option together with the /testlist option. The following command, for example, is run in the solution folder. Because the test metadata file also resides in that folder, no path is necessary:
MSTest /testmetadata:Bank.vsmdi /testlist:balancetests
Detailed :
To run tests from the command line
1.
Open a Visual Studio command prompt.
To do this, click Start, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio Command Prompt (2010).
By default, the Visual Studio command prompt opens to the following folder:
:\Program Files\Microsoft Visual Studio 10.0\VC
Note
To change the folder to which the command prompt window opens by default, click Start, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, right-click Visual Studio Command Prompt (2010), and then click Properties. In the Visual Studio Command Prompt (2010) Properties dialog box, you can change the path to the default folder in the Start in box.
2.
Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.
To identify your solution folder, first identify the Visual Studio Projects folder. To do this, click Options on the Tools menu in Visual Studio, and then click Projects and Solutions. Under Visual Studio projects location, you see a path such as the following:
:\Documents and Settings\\My Documents\Visual Studio\Projects
Your solution folder is typically a child of this Projects folder, such as the Bank folder in the following example:
:\Documents and Settings\\My Documents\Visual Studio\Projects\Bank
3.
Run the MSTest.exe program.
When you run MSTest.exe, you must specify either a test metadata file or a test container, using either the /testmetadata option or the /testcontainer option, respectively. You use the /testmetadata option only once, to indicate one test metadata file. You can use the /testcontainer option multiple times, to indicate multiple test containers.
If necessary, include the path to the folder in which the metadata file or test container resides. Test metadata files reside in the solution folder.
Depending on the test type, test containers are XML files, assemblies built from test projects, or other files that reside in the folders of a test project.
Source: http://msdn.microsoft.com/en-us/library/ms182487(v=vs.100).aspx
Try this
mstest.exe /testcontainer:c:\projects\MyTests\Sampe.Tests.dll

Fast Re-build C# app under Windows 7

Need to recompile my project (not large) under Windows 7 without setting up Visual Studio.
Is there any method to do that with minimum setup procedure. It's C# app, using System.Net.Sockets and some others from my other projects.
Should I set up whole VS to recompile just little code app? like batch build..
Or... is there any cloud/public servers with pre-installed different Operational Systems with Visual Studio, where I could upload my project and just re-build it under all platforms at once?
I use this batch script to compile my C# applications. Just pass in the solution name without the .sln extension
if exist %SYSTEMROOT%\Microsoft.NET\Framework\v3.5 set MSBUILDPATH=%SYSTEMROOT%\Microsoft.NET\Framework\v3.5
if exist %SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319 set MSBUILDPATH=%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319
set MSBUILD=%MSBUILDPATH%\msbuild.exe
%MSBUILD% /nologo /m /p:BuildInParallel=true /p:Configuration=Release /p:Platform="Any CPU" "%1.sln"
Do you just want to use studio to compile without running the GUI? If so, you have at lot less work to do. Use devenv.exe.
http://msdn.microsoft.com/en-us/library/xee0c8y7%28v=vs.80%29.aspx
This should work for you:
csc /r:Reference1.DLL /r:Reference2.DLL /r:Reference3.DLL Main.cs...other cs
/r: pass refereences of your project
after, pass cs files separated by space
In order to run this in CMD o PowerShell, you may need to run *vcvars32.bat, which you can copy from machine where you have VS installed, or just, before inserting command, set complete path to csc.exe*
Regards.
With the .net Framework installed, you can just use msbuild or csc.exe.
Build project on commandline with msbuild.exe (comes with the framework).
No need to use devenv (which is vs) or csc (which requires you to specify dependencies etc.)

why no output when use command line to build VS setup project?

I have installed Visual Studio 2008 on our build machine because we want to build the setup project to create MSI installer for our C# application.
From IDE, it works fine. The installer is created as expected.
Switch to command line, with the follow command the process finished without any error but there is no output (no installer created)
DevEnv.exe .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
change the /build to /deploy to /rebuild have no difference (no installer created)
I am doing anything wrong?
I just fought with a similar issue, where I'd run the devenv.exe and get no feedback and no output, even with the /Log flag. This is the exact same call I'd use in 2005, and it worked like a charm. But then I found a devenv.com in the same folder, so I tried that, and it ran as expected. I don't know the difference between the .com and .exe versions, but you might try that.
I think the problem is that you are running DevEnv.exe and not DevEnv.com.
This should output to the console.
DevEnv .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
Try building the solution file instead of the vdproj file in your command line statement
There must be at least one project in the solution that form the output of the installer project. These will need to be built as well.
Interesting question. I thought this would be pretty easy as well. I was able to easily do a release build by opening a VS2008 command prompt in the folder with my vdproj and running:
devenv SomeName.vdproj /build
But release was a lot trickier. After a few failed attempts on my own, this guy showed the way. For some reason, the fully qualified path to the sln and the vdproj seemed to do the trick (again I was in a VS2008 command prompt but this time I was in the SLN folder):
devenv "C:\SomePath\SomeSlnName.sln"
/rebuild Debug /project
"C:\SomePath\ProjectFolder\SomeProjectName.vdproj"
/projectconfig Debug
It doesn't make sense to create an installer for the Debug build, you always want the Release build.
If that's really necessary then open the .vdproj in Visual Studio, Build + Configuration Manager and tick the Build checkbox for the Debug configuration. Beware that this property is stored in the .sln file, not the .vdproj file so click File + Save All to let VS write the solution file.

Creating msbuild script to build, publish with specified app.config, and update from different locations

I have googled everywhere for this solution and cannot find anything!
I want to have a msbuild script to do the following:
Build the project solution
Publish the built solution with the specified app.config (app.config.debug or app.config.release) to a specified folder (Development or Production)
With the specified configuration, know where to check for updates.
-if deployment -> check in the sample production folder
-if development -> check in the sample development folder
The script currently works but there are two problems...
I cannot figure out how to have two different installations that check two different places to check for updates.
I cannot auto increment the revision build. It currently stays at the same build number everytime i use the script.
My Current script:
msbuild "C:\sample\sample.csproj"
/t:clean
/t:build
/t:publish
/p:Configuration=release
/property:PublishDir="C:\Samplelocation/"
/property:UpdatedEnabled=true
/property:UpdateRequired=true
/property:UpdateUrl="C:\Samplelocation/"
/property:GenerateManifests=true
/property:PublishWizardCompleted=true
Any help would be greatly appreciated. Thanks ahead of time!
You should take a look at MSBuild Batching.
Here are some links on batching:
MSBuild Batching Part 1
MSBuild Batching Part 2
MSBuild Batching Part 3
MSBuild RE: Enforcing the Build Agent in a Team Build

Categories