I want to add a small piece of information such as a software package version I have on my machine to my C# executable.
I want this info pulled on the fly during every build of my program. The info is just 1 line in a text file saved somewhere on C:\
The info needs to be accessible to my program, when I click a button within it, it should display that line of text it grabbed during the build.
Perhaps this could be accomplished by putting the info into a custom environment variable, which gets propagated during a build by adding a before build target. Not sure how to do that, if its even possible. Im using VS2008.
Please share your ideas!
VStudio has the option of performing pre-build steps. In our build, we have a batch file that executes tools that in turn generate a small file of C# which is then built by the build process. It's not very elegant, but has the benefit of simplicity and it works.
If you are the only person to be building this (or everyone building it has this text file in the same location), you could add your text file to your project as a linked item.
This way the file would be included with your project without creating a copy so any updates to it would be propagated to your project.
Right-click the project in solution explorer
Add->Existing Item...
Once you have navigated to your text file, click the down arrow icon at the right edge of the add button and select "Add as Link"
These steps are copied from this answer to a different question. That question was dealing with VS2010, but this should work in VS2008 just the same.
Related
I have a C# WPF application. It has two icon files as resources - one for use when creating a release build, and the other for test builds. It is currently using 4.7.2 - but I am are planning to migrate it to .NET Core soon.
When I am generating a build, I set the icon file via the Properties-Application page.
Since I can't find a way to conditionally set the desktop icon file reliably when building, I thought I would simply check the icon file at runtime to see if it is the correct one for the build type. I do not want to have the wrong icon file used.
Why do I care? There are a number of users who might have the test and live version on their desktop at the same time. I want to make sure that the test versions can not be confused with the live version.
It may not seem like much, but often, support people remote in and most of them won't know about the test version - hence the need to avoid any confusion.
If you have a better way to set the desktop than setting the icon at build time, that would be appreciated too.
I can get the icon using ExtractAssocatedIcon() - but that doesn't indicate the name of the icon file.
You could do the following to set the icon at build time.
Here are some steps:
Create your project and add your .ico files.
Right click the project and select Unload Project.
Right click the unloaded project and select Edit Project File.
Inside of the project file there will be <PropertyGroup> xml tags for your various builds.
Set the <ApplicationIcon> xml element for each build configuration.
Now when you run the build in either Debug or Release the .ico file that is used will change.
I recently started using Git with Visual Studio 2015 and I'm trying to modify the properties of an installer project. The issue is that it won't let me because the project isn't checked out and I don't see an option to check out the project with Git through Visual Studio. The only place I even see the mention of the words 'Check Out' is under branches and it's grayed out.
I'm having the same problem in VS2015. It seems to be an issue with the Installer Project extension. For some reason Visual Studio doesn't detect when you attempt to change the Setup Project file (with YourProject.vdproj), and doesn't automatically unlock it for you. I had the same problem with TFS, but in that case all you had to do is manually unlock the file, by right clicking on it. I've just migrated to Git, and the problem is still there, but now you can't unlock the file by right-clicking on it (since there is no explicit check-out in git).
I'm still looking into the problem, but the only solution I've come up with now, is making a quick manual edit of YourProject.vdproj in Notepad. Visual Studio WILL recognize that edit, and unlock the file for you. After that you can continue to use IDE to make changes to the Installer project.
Unfortunately, the problem comes back once you check in your changes, and try to modify the file again. You will once more have to manually edit it to force Visual Studio to unlock it for you.
EDIT: After spending a few hours on this, I finally came up with a proper fix, which I verified works on a few in-house projects. Here are the steps:
Open your solution file in notepad, and delete the following section: GlobalSection(TeamFoundationVersionControl)
Open the solution containing locked Setup Project in Visual Studio.
Go to Tools > Options > Source Control > Plug-in Selection, and pick 'None' from the dropdown.
Click Yes to the dialog that warns you the project will be closed.
Open the solution again, you will be prompted to permanently remove
source control bindings from the projects. Click Yes to that.
You can now go back to Tools > Options > Source Control > Plug-in
Selection and pick Git again.
At this point the problem is fixed, and you will be able to modify
your Setup Project without any issues.
I found that removing bindings is clearing the values of the following tags from the project files:
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
Apparently SAK stands for 'Should Already Know'.
Here is a workaround I found,
Mark the project installer in the Solution explorer, And click "Save" (not save all).
For me it did the trick.
If it's still didn't help try to reopen VS and try the method again.
Cheers!
Open a command line, go to where you need to check it out, then issue the git checkout command? http://git-scm.com/docs/git-checkout
Like Eternal21 I encountered this problem when trying to modify an Installer project, this was in a VS2013 (rather than VS2015) project though and I could not see a GlobalSection(TeamFoundationVersionControl) in the solution file. However the following steps worked;
Go to Tools > Options > Source Control > Plug-in Selection, and pick 'None' from the dropdown.
Make the change required to the Installer project
Go back to Tools > Options > Source Control > Plug-in Selection and select Git again.
(and the Solution did not ask to be closed).
You need to create a new empty repo on your Git server first, then clone it to a folder on your local computer.
After that you will be able to add your project and check it in by adding it to the local folder.
I was able to work around this problem by simply editing the vdproj file (setup project file) manually in Notepad++ (you can use any text editor), making some temporary changes into it (type a character and backspace) and saving the file. This effectively checks out the project from GIT. Now you can come back to Visual Studio and make whatever changes you want.
I was able to use dotNETs suggestions and edit the vdproj file. Simply adding a character and removing didn't work, but making an actual edit did. Doing so triggered the check out for GIT. In my case I was attempting to change one of the Detected Dependencies exclude property to false and was able to do so while editing the vdproj file. Once I saved it then reopened Visual Studio the check was displayed on my installer and the change was already applied. I was able to make additional changes while checked out.
Once finished and I checked it in, I could no longer edit and needed to manually edit the file again to check out.
Is it possible to do these 3 things programmatically in Visual Studio:
Include new files to a project
Change 'Build Action' on a file in a project
I need to do this from a command prompt application but not sure if it is possible??
Yeah this is quite possible. You can create templates as .txt files with variables like $$$my_variable$$$ and just replace those with your inputted values. Can do whatever you want really. If you need an example, you could take a look at OrchardCMS, they have a command line generation tool that creates files/projects.
http://orchard.codeplex.com/SourceControl/latest#src/Orchard.Web/Modules/Orchard.CodeGeneration/Services/CodeGenerationCommandInterpreter.cs
That is the file that contains the relevant code, there is a folder in that project with the templates. Hope that points you in the right direction!
Or maybe access it's data via reflection somehow ?
Thanks
EDIT: I'd like to know if there's a way to do it without reading it as an XML.
Like a ms library that supports it, so it'll work for any kind of project and any kind of vs version (2005, 2008, 2010 ... ).
The *.csproj file is really just an XML file. You can open it just like any other XML file and treat it as such as well. Realize that any changes made to it, though, will require reloading the project.
Also, remember, there is no *.csproj file once the application is compiled/deployed.
Yes, you can open it in a text editor, or from Visual Studio
Right click on a project
Unload Project
Right click on the unloaded project
Edit project
Right clicking the project and selecting the properties option gives you a GUI to change some of the settings in the project file. Also, when you right click a file and change it's properties it causes a change in the project file. If you want to do anything very serious, like add custom build steps, you have to do it by hand in a text editor like notepad++. It's just an XML file. If you're familiar with MSBuild the proj file has many similarities to a build script for MSBuild.
I have tried creating an install file but it never includes the database in the output, I have run into this problem a few times and most of the answers I find online are too cryptic for me to wrap my head around.
In the Project menu, select Add existing item, change the file type to Data Files and select your database. Then go to your project properties, in the publish tab, click the Application Files button and make sure your access file is include.
If you include your MDB as a resource (Properties -> Build Action -> Embedded Resource) you can extract it using: Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
See here for a complete sample (that also decompresses):
http://code.google.com/p/videobrowser/source/browse/trunk/MtnFrameGrabProvider/Plugin.cs