Fast Re-build C# app under Windows 7 - c#

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.)

Related

How to embed the version information in the executable file name when building C# application in Visual Studio?

This question is a complement for the post How to change the output name of an executable built by Visual Studio.
After reading this post I did the following:
Firstly, I followed the answer for this post and I could define the executable file name successfully.
Now, I would like to know if instead of only define the name as "Demo.exe" as mentioned in the example post above, it would be possible to embed the version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute in the built file, resulting in something like "Demo_v1.0.0.0.exe"?
I'm developing my application in C# WinForms, using Visual Studio Express 2017.
Why would you want to change the name of the executable? Whenever you try building a Setup for your application, you need to change the Setup to include the new file. And when you install an update, your Setup needs to know all versions of your executable in order to delete the old version. That's just not what you want to do.
If you want to keep all versions of the software for yourself, come up with a different solution, e.g. moving the executable into a folder which has the version number.
That said, I have done this for Setups, so customers can download different versions of the Setup. I did that using a commercial tool called Visual Build, but there are other build automation tools available. So, my answer is: set up a continuous integration / continuous delivery pipeline (CI/CD) and automate the step there, not in Visual Studio.
From the project properties, you can add Post build event command line to rename your exe
pseudo
Maybe you can create another console renamer.exe which reads version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute of your app and renames it and then call that renamer.exe from Post build event command line
write a powershell script to rename the newly built exe and call that script from Post build event command line

How to create more Macros in C# Post build step

I have an Visual Studio 2012 Solution that includes both C# and C++ projects.
I want to create a postbuild step and I notice that the C++ projects have much more macros than the C# projects. I need to get the WindowsSDKDir which is available in the C++ macros but not in the C# macros.
C++ Macros
C# Macros
Can I see all the Macros that are available to the C++ projects in the C# projects??
I can think about the following workaround. Write this post-build command:
$(ProjectDir)post_build.bat
Create post_build.bat file in the project directory and fill it by this way:
echo %WindowsSdkDir%
echo %WinDir%
Build the project, it prints:
ECHO is on.
C:\Windows
So, C# is not smart enough to see Visual Studio build environment variables (%WindowsSdkDir% is expanded to nothing), but at least general environment variable like WinDir is expanded. So, you can create your own environment variable with the same value as WindowsSDKDir and use it in batch file called from Post-Build step.
To make something more useful then echo, create batch file with parameters (%1%, %2% etc.) and call it from post-build step, passing required parameters. For example:
$(ProjectDir)post_build.bat $(TargetPath)
In the batch file %1% will be expanded as output file name.
Simply call the batch file that sets up environment variables for a Visual Studio command prompt as the first line of your build event. This will set up all the environment variables for use in later lines of your build event. For example...
call "$(DevEnvDir)..\..\VC\vcvarsall.bat"
"%WindowsSdkDir%bin\x86\rc.exe" <parameters>
Note that the environment variables are Windows environment variables and need to be accessed via the %VAR_NAME% syntax rather than the $(VAR_NAME) syntax.
The location of the vcvarsall.bat file is consistent over at least VS2012, 2013 and 2015, meaning that this solution is generic and doesn't need tweaking for different VS versions.
If you use msbuild you will find that $(DevEnvDir) is not set correctly when building in msbuild. In that case, this alternative should work for both msbuild and visual studio build providing you have not customized the visual studio install location.
call "%ProgramFiles(x86)%\Microsoft Visual Studio $(VisualStudioVersion)\VC\vcvarsall.bat"

Compiling an executable file using Notepad++ and Csscript

I am very new to C# and am wanting to write my code using a text editor like Notepad++ and compile using csscript. I have the two working and I am getting results from my code.
However, so far, I have only been able to run my code as interpreted, but I will eventually want to compile exe or dll files.
Am I able to compile my code into a standalone exe or dll using notepad++ and csscript, please?
Just an update for your original question...
CS-Script plugin for Notepad++ actually allows building normal executables that can be executed as any other managed exe.
Little too late, but here's the one that worked for me: I called this batch script bnr.bat (Build and Run)
echo Building project..
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /out:"%1\%2.exe" %3
echo Running project
%1\%2.exe
pause
Save this bnr.bat file and and then use NPP's Run and set The Program to Run as follows and before you press Run button, press Save and provide your custom shortcut keys:
<directory_where_you_saved_bnr.bat>\bnr.bat $(CURRENT_DIRECTORY) $(NAME_PART) $(FULL_CURRENT_PATH)
the $ constants are defined internally in NPP:
$(CURRENT_DIRECTORY) is the full path of the directory containing your C# file.
$(NAME_PART) is the name of your C# file minus extension (.cs).
$(FULL_CURRENT_PATH) is the full path for your C# file.
This does not have any error checking, but pause in batch script will allow you to see the errors and exceptions within the console before you exit the script.
I had set the PATH environment variabile, but somehow this batch script did not find csc.exe, because it was looking at the npp bin directory.
For .NET 5+ (and .NET Core), you can compile your project using the .NET Command Line Interface (CLI)
The command
dotnet publish
creates the files you need to run your program.
No, you will need a compiler (Microsoft´s from VS or Mono)
csc.exe is what you need. It should be at C:\Windows\Microsoft.NET\Framework\v4.0.30319.
Here is a link to a reference. http://msdn.microsoft.com/en-us/library/2fdbz5xd.aspx
And check out Visual Studio express, it makes life easier.
Thanks for the reply.
I have Visual studio but the license expires in 7-days.
I am using Notepad++ with an add-in called cs-script. The add-in checks and runs code in a similar manner to Visual studio but it will not compile an exe or dll file.
However, to answer my own question and as suggested by quarksoup, the answer lies within the csc comiler. By using the /flags, I am able to compile my programs from the command-line. I shall write a batch file that will do the work for me.
Regards

How can I programmatically build my solution files from C# code?

I have a large solution containing many projects with one of them being a Setup project. There are also many current versions stored in separate branches. I have a build tool that used to work in .NET 2, but hasn't worked since we upgraded to .NET 4.
Internally, the new .NET 4 version of the build tool uses Microsoft.TeamFoundation.Client.RegisteredTfsConnections.GetProjectCollections() and versionControlServer.GetAllTeamProjects(false) to get a collection of TeamProjects from my TFS source control server.
I then display them visually in the UI and when a user clicks on a particular solution version, the application calls the following to get the latest for that solution version:
workspace.Get(new string[] { serverPath }, VersionSpec.Latest, RecursionType.Full,
GetOptions.GetAll);
The application used to build the solution files and this would include the Setup project. At this stage, the setup project would create an MSI that the application could be installed with. It is this last step that I am having problems with.
I need to be able to programmatically build the solution that the user selected using C# code. The working .NET 2 code for this was as follows:
Process process = new Process();
ProcessStartInfo processStartInfo = process.StartInfo;
processStartInfo.FileName = processName;
processStartInfo.Arguments = string.Format(" \"{0}\" /BUILD \"Release|Any CPU\"",
solutionPath);
processStartInfo.WorkingDirectory = processDirectory;
process.Start();
There is no error when this is run, but it no longer launches Visual Studio and builds the code. Clearly, this was a poor way to do it initially, but I can't find the 'correct' way using the TFS classes.
I also tried running MSBuild.exe directly (similar to the above example), and this does build the solution, but for some reason does not build the Setup project that produces the MSI. Note that I do NOT use any manually created build files.
Unfortunately, useful documentation for the Microsoft.TeamFoundation namespace is hard to find! I'm hoping that someone here has made use of these classes and can direct me to a solution to this problem.
If at all possible, I need to use .NET classes (eg. not Process.Start) as I really need to know when the build has finished as well. I can however set up a FileSystemWatcher object for this if this is asking too much.
msbuild skips the installer projects because it doesn't know how to build them. FinalBuilder shells out to devenv.exe to build these.
Calling `devenv /build "Release|Any CPU" /project "MyInstaller.vdproj" should run the build you need from the command line, without starting the VS GUI. Try it!
With all that said: We, too, use FinalBuilder, and VS Installer is deprecated, so you'll probably want to plan on replacing that.
It turns out that the problem was unfortunately completely unrelated. The .NET 2 code that was to be updated had hard coded 'Program Files' into the devenv.exe file path - however the new computers are 64bit and Visual Studio 2010 is installed into 'Program Files (x86)'!
So this means that the above code sample DOES work and WILL allow me to build the solutions from C#. It's not the object oriented way that I would have preferred to do it, but after all your comments, I'm just glad to have got it working at all.
Thanks for your time everyone.

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.

Categories