Link resource file to multiple projects - c#

I have two projects A|B. A is a creator and B is a consumer of what A creates. Each project needs to use a global.txt file which has configurations. Each project has its own solution in TFS. Is there a way to link global.txt from a location in TFS into each project so that if someone edits the global.txt, then rebuilds project A it will contain the updated file without having to update it manually

When you configure the source repositories in the build definitions separately for two solutions, you could both include the global.txt file mapping.
At the beginning of the build process, the agent downloads files from your remote repository(on TFS) into a local sources directory(build agent).
Then set a CI trigger , the builds will run whenever some changes made to global.txt and checked in.

Related

Jenkins - Change destination of built project

I have a C# web application that I have developed using Visual Studio 2010 and commit changes to a VisualSVN repository using the AnkhSVN plugin for Visual Studio.
I have created a Jenkins project that checks the repository every five minutes for new commits and then builds the web application, using the MSBuild plugin, if it sees a change.
This is working fine, however it is building the application to C:\Program Files (x86)\Jenkins\workspace\[Jenkins Project Name]\[Web Application Name] and I would like it to build to D:\Web\[Web Application Name] as this is the directory my IIS site is pointing at. (Both locations are on the same server)
Is there a setting in the Jenkins project where I can change this or do I have to add a build step that copies to a different location using a batch command or something similar?
Many thanks in advance.
You can specify a custom workspace for the Jenkins job to run in.
In your jenkins job look for a button on the right hand side that is labeled Advanced. On Jenkins 2.46.1 it is at the bottom of the General section just before the SCM section of the build job. Click on it and a new set of options will appear, one of them will be Use custom workspace. Check the box and put in the path to the folder you want to use. You should ensure the Jenkins user has permissions on this folder or bad things might happen.
Note that this will perform the entire build in this folder, so anything else that is also in the workspace folder for that build job will be in the new location.
If you want just the output files without all the source and other stuff you will indeed have to add another build step (batch is one option) to copy the relevant files from your build jobs workspace (which can be accessed in batch using the WORKSPACE variable jenkins defines for the job) to the desired destination folder.

How to create folder in mvc solution directory so that it is included in project?

I am new in mvc and c# and I can't solve following problem:
I am trying to create a folder named "Items" in solution folder.
I have tryed to use CreateDirectory method:
Directory.CreateDirectory("~/Images");
But it didn't work for me - folder wasn't created ..
Partly working solution was to create a folder by :
Directory.CreateDirectory(Server.MapPath("~/Images"));
"Items" folder was created, but it is not included in the solution:
How to create folder in solution directory so that it is included in project ?
(I needs to by done by code not by hand)
You need to understand what solution and csproj file is used for
In general, they're being designed and used for development with Visual Studio, and once the project is compiled, all these files will be ignored and excluded from the deployment package
Directory.CreateDirectory(Server.MapPath("~/Images"));
The code above simply create the directory if not existed yet in the deployment package at run-time, so you won't see it in your solution unless you run the project locally (either debug/release mode, it does not matter here). However, everything will run normally in hosted environment (ex: IIS).
For your information, here's the brief of what solution and csproj is
solution (.sln) file: contains information to manage one or many individual projects, contains build environments (for each project), start up mode (useful when you want to start multiple projects in one run), project dependencies and so on. Take a note that VS also read from suo file (solution user options) which is used to defined user-custom preferences (you should not include the .suo file in the version control, because it's custom settings)
csproj file: define the structures of project, what the namespace is, what is static folders, embedded resources, references, packages, etc.
Lastly, if you create the folder manually, VS will auto include that folder into deployment package AND csproj, but depends on the file type, you might need to change the Build Action and Copy To Output Directory in file properties.
Hope it helps.
A deployed web application on a web server doesn't have any notion of Visual Studio solution or projects. So the Directory.CreateDirectory(Server.MapPath("~/Images")) is the correct way to create a folder inside your web application at runtime but we cannot be talking about including it into a solution because this hardly makes sense in a pre-compiled web application. If you create the directory on your local development machine, you could always manually include the folder to the corresponding .csproj file, but at runtime this will not make any difference whatsoever.
The reason I wanted to create a folder (if didn't exist) was to make sure it exits before I try to store image in it.
After reading posts here and a few google searches I have concluded that the proper way to handle image upload would be
To create (In my case) folder "Images" by hand to be sure it exists
Then storing uploaded img in existing folder:
string path =Server.MapPath("~/Images/"+ UploadedImageName);
file.SaveAs(path);

TFS update a project

I am a software developer working on a webshop. We are using nopCommerce 3.30 with custom plugins. The whole project is checked in on a TFS server. (Visual studio 2013, Team Foundation server 2012)
The problem is the following:
nopCommerce 3.40 was released, we downloaded the ZIP with the source code, but i am not sure how do i compare the diferences and check-in the new version. I can't just replace all files because i need to compare the folder structure / delete the files and folders that are not in 3.40 version.
Is there any compare function between 2 projects on either the client or server side ?
If you're using local workspaces, you can just delete all the code in your workspace, then copy the new code into the same workspace folder. Then examine the pending changes window. TFS will automatically detect all add/deletes/edits (you may have to promote some of the changes from the Excluded Changes section of the Pending Changes window).
extract the files to a local folder, you can then use the compare tool.
Map one side to the source location of the original package, map the other side to your local directory. this will show you differences in the folder structure, file names etc. you can repeat / drill down to do the same at the file level

Deploy different WCF .svc files based on configuration

I have a Service1.svc file that is a normal WCF service. If I deploy the WCF project it will happily copy the Service1.svc file along with the binaries and the other files. So far, so good. What I want is, based on the selected build configuration, or some other trick, to publish different contents for the Service1.svc file.
Let's say I have a Service1.Conf1.svc file and a Service1.Conf2.svc file and two configurations (like Debug or Release) that are named Conf1 and Conf2. When I click publish and have the Conf1 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf1.svc. When I click publish and have the Conf2 configuration selected, I want the publish folder to have a virtually created Service1.svc file whose contents are from Service1.Conf2.svc.
I would like to have this for the publish action, not the build action (which could be achievable by a post-build or pre-build event). The main purpose is to adjust the contents of the Service1.svc file according to the publish environment.
Any ideas?
We took a different approach and generate all required config/svc files for all possible installs (using TT file generation) and let the installer copy the correct configs/svc files (based on user selection during install).
The names of the files are constructed by inserting the target platform name into the standard name e.g web.local.config, web.dev.config, web.test.config etc
This way you can give one installer to anyone from any department. They just choose the platform.

System.Addin & ClickOnce

I have a annoying build process from using System.Addins API with ClickOnce. Using System.Addins requires a specific directory structure, and the main project does not reference the adapters, view, and contract directly, which doesn't work well with the ClickOnce architechture.
The annoying part with the build process is that I have to copy, via post build event, the .dlls from the add-in components into the directory of the main app project, then reference those files manually from the main project, so that ClickOnce will include them. Firstly, this takes 2 iterations of build to get it to build correctly, secondly, it interferes with source control (I have to exclude the copied add-in dll files from source control or any changes made to them would require checkout).
So, my question is, is there a way around this hack? Something more elegant?
I can't fully answer your question, but it appears you are creating ClickOnce deployments through Visual Studio. I would ditch that method and use MageUI instead. It's a stand-alone executable that can be found in the framework SDK that will generate your application and deployment manifest files. It comes with a gui version (mageui.exe) and a command line version (mage.exe).
Mage may not get rid of your post-build event but it should do away with having to reference the files to get ClickOnce to see them.
Thanks for your input, I am currently doing it the way you mentioned; creating the folder in my project, and include the dlls that I need. It works, but it's an ugly solution, and it interferes with Source Control.
I'm aware of the limitations of ClickOnce, I was hoping there may be a way around it. For example, I read somewhere that I can use deployment projects to create the appropriate dependencies needed in a specific structure. The problem with that is once it is deployed to the public, there is no easy way (within ClickOnce) to update those dependencies.
The solution I use is to have a single output folder for all projects. Every project puts it's own files in the correct subfolder. The application bootstrapper project puts his dlls also in the output (root) folder. When you then create a click-ones for the bootstrapper, it will take all the content from the output folder.
The hardest part is to actually get all the dll's in the right place (and have every dll only once)
I solved this problem by adding the pipeline assemblies as content into the main solution structure.
To do this, change the output folder from (/bin/debug /bin/Release) to something else. I used ../lib otherwise you would get a visual studio cannot reference this file error.
Create the pipeline folders in your main solution
\AddInSideAdapters
\AddInViews
\Contracts
\HostSideAdapters
Right click on each of the folders and click "add existing item" change to view all files and then browse to your ../lib (or wherever you have the output set) and then pull down the add button (click the down arrow) and click "Add as a Link".
Right click on each file and set it to Content.
This will create a refresh file pointed to your assemblies and they will be included into the clickonce manifest.
ClickOnce do not let you install the software where you want. It will install the binary and dlls in the documents and settings. You can in your project properties go in the Publish tab and select Application Files to select additional file to Include. If the System.Addings require dll in a specific folder relatively to your assembly, you might just create the folder in you project and includes from here the dlls. This might works. If not, I do not have "hack" or other solution, clickonce is great but limited with some functionalities.

Categories

Resources