In Visual C# 2008, I have a solution with two projects.
First project contains Form1 that displays one Label with Text set to a string from Properties.Resources, like this:
label1.Text = Properties.Resources.MY_TEXT;
In the second project, I "Add as link" this Form1 from the first project. I want to show this form, so it displays the same as when called from the first project. It should show a label with text Properties.Resources.MY_TEXT defined in the first project.
Unfornately, the second project doesn't build with the following error message: "The name 'Properties' does not exist in the current context".
Is there any way how to resolve this? I have tried to "Add as link" the "Resources.resx" file from the first project, but it doesn't help.
EDIT: I found that if I add Project1 as a Reference in Project2, everything works. I also had to change Access Modifier in the Project1 resources from Internal to Public. Is this the right approach?
Thank you,
Petr
Yes that is the right approach (referencing one project from another). A pattern you may like to apply is to have one project that has all your reference/lookup/settings in it. Then you don't need to work out dependencies between your UI projects.
Your approach of making the resources public is the correct.
You also asked about combining assemblies. Have a look at the ILMerge tool.
You should add "using MyOtherProjectNamespace" so that you can access its properties
Related
I have a solution with over 170 projects in it. I recently needed to add two more projects to this solution. For reasons that are not relevant to this question, the solution is built as at x86.
When I open Configuration Manager, and scroll to my new projects, they say "Any CPU". To change that I select <New...>:
It brings up a dialog to make the new entry. I fill it out like this:
When I select OK, it flashes for a second, then goes back to "Any CPU":
I also tried selecting <Edit...> and I get this:
The Remove button is locked out and I don't have any other options.
How can I get an x86 option setup for my new projects?
I faced a similar problem when I converted C# projects into C# SDK style projects.
I found that after conversion, the project type GUID in the solution file did not change from Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = ... to Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = ....
Solution of this problem in my case was to delete this project from VS solution and add it again. You can also manually edit solution file (.sln) and change wrong project-type-GUID.
In your case, try to check the project type GUID in the solution file and change GUID manually. The list of project type GUIDs can be viewed here.
Context: setting up the Assembly Name/Default namespace in the Project Properties (right click on project, Properties, Application tab; or edit the .csproj).
I would like to add a parameter there to explicitly have them following the Project Name, plus some custom suffix. So if I rename my project, the Assembly name/namespace follow that rename.
Example: project named foo → foo_suffix.dll. If I rename the project to foo1 → foo1_suffix.dll.
Same behaviour for the namespace.
Reading Common macros for MSBuild commands and properties,
I tried inputting $(ProjectName) both in VS and in the .csproj file, but I get a .dll named exactly like that.
How can I get this done?
How can I get this done?
1. Try using $(MSBuildProjectName) property from this document.
You're developing a C# project(csproj) while your document above is about macros in C++ projects(vcxproj). So I think $(MSBuildProjectName) property can be more suitable for you after my several tests.
(I tried $(ProjectName), but it only worked well when I set something like <AssemblyName>$(ProjectName)</AssemblyName>, if I add a suffix like $(ProjectName)_suffix, the output sometimes is _suffix.dll. But it always work well if I use $(MSBuildProjectName)!)
I get the desired behaviour, but that is inconsistent with what I can
see in project, Properties, Application tab.
2. Try reloading the project file(Right-click project, unload.., reload...) to Update the UI.
From your comment, it seems like the $(ProjectName)_suffix works well in your machine? If so, you can still use $(ProjectName) property.
What you experienced is expected behavior for Msbuild and VS. VS will read value from csproj during project loading process. Then it display the related value by UI.
So after we rename the project name and then build the project, we can get a ProjectName_suffix.dll in output folder. But the UI is still not changed(inconsistent), cause now we need to Update the UI.
You can right-click project node, unload the project=>reload the project to get UI updated. And now the output xx.dll can be consistent with what you see in project, Properties, Application tab. It needs us to reload the project each time after you rename the project, then the UI would be consistent with your xx.dll. And actually it won't affect your build though the UI is not updated, the output can be your desired behaviour.
3. All above is more related to the relationship between Assembly Name and Project Name. One point you should know is msbuild(csproj) won't modify the source files(xx.cs) after the project is created.
So assuming you have a Class1.cs file whose namespace is Library. If you rename the project to NewLibrary, reload the project and you can see the Namespace is NewLibrary now in project, Properties, Application tab. But the namespace for Class1.cs file is still old Library. This is expected behavior in VS, and the new NameSpace NewLibrary would work if you create a new xx.cs file.
Hope all above helps :)
I just downloaded an asp.net project from my work's team server and it seems like a bunch of references aren't working. If I go to the references folder in the solution explorer many of them have a little yellow caution sign next to them and if I click on one them it says something like "this project cannot be viewed in the object browser ". I can't find them in the add references library either. How can I correct this?
most of them are asp.net, doNoNotOpenAuth or similar web refs
thanks
It sounds like someone added a reference to a path which doesn't exist on your system.If you right-click one of the missing references and choose Properties from the popup menu you will be able to see the path that has been set for the reference and verify if that is the case.
If your team is not already doing it, I would recommend copying third-party DLLs to a central folder under source control e.g. /lib and add all references from there to ensure that there are no path discrepancies in future.
I am manually reconstructing a WCF service from pieces. I add a MyService.svc file MyService.svc.cs file.
How the heck do I now make the latter the code-behind of the former? It's not just a matter of editing the project file to add the dependency and editing the svc file to point to the code behind file. Neither of those, nor the combination, works for me.
I also tried right click remove from project then include, which I seem to recall used to work for asp.net pages in one or another version of Visual Studio.
I just got it to work. Remove from project and then include in project actually does work. The trick is to make sure the files have the same names, except for the extensions. Although I called them both MyService in the question, in fact they had different names which was why it wasn't working.
So:
Make sure the roots are the same name.
You don't need to edit the project file or the markup file to point to the code behind.
Right click and exclude from the project.
Ensure Show All Files is active (top of solution explorer)
Ctrl-click to select both files.
Right click and select include in project.
They will be associated as markup and code behind.
I'm using Visual Studio 2008 and would like to create a sort of container project that holds a number of DLL's that must be installed with a solution. I want them to be in a separate project so that they can be easily attached to a solution as a group.
I created an empty project call TEST, added my DLL's to it with a Build Action of "Content", and set them to "Copy Always". That all works exactly as I want. The problem is that if I set the TEST project Output Type to "Console Application" or "Windows Application" that it won't build because there's no entry point. If I set the Output Type to "Class Library", it builds but I end up with an extra TEST.DLL file that I don't really want.
Is there anyway to sort of set the Output Type to "none"? I want the build actions to take place (so my DLL's get copied) but I don't want the dummy class assembly created. Any ideas?
Thanks!
Assumptions for the following step-by-step guide:
Let's assume that you have a solution with two projects:
Main: your main (start-up) project.
BundledDLLs: a library project which contains the .dlls that should end up in the main project's output directory.
Step-by-step guide:
The easiest way to achieve your goal inside Visual Studio is probably the following:
Add all .dlls to BundledDLLs and set their Copy to output directory to Copy if newer.
This is done in the Project Explorer and the Properties windows.
Configure BundledDLLs's output directory to be identical to Main's output directory.
This can be done in the Build tab of BundledDLL's Project Properties page. Enter something like the following in the Output Path textbox:
..\Main\bin\Debug
Set up BundledDLLs as a dependency of Main.
Do not add BundledDLLs as a project reference to Main, as you usually might; instead, use the Project Dependencies dialog to . This will tell the build tool that whenever Main is built, BundledDLLs needs to be built first.
Do this by right-clicking on the Main project node to open the context menu; select Project dependencies... from there. In the now opened dialog, first select Main from the drop-down list; then check BundledDLLs in the project list below. BundledDLLs is now registered as a dependency of Main.
P.S.: One disadvantage of not having an explicit assembly reference in Main is that some tooling might not recognise the dependency. For example, ClickOnce deployment might not work properly.
Add a post-build event to BundledDLLs that deletes the superfluous BundledDLLs.dll.
As you said, you don't want, and don't need, the dummy output generated when BundledDLLs is built. So add a post-build event that simply deletes this .dll once it's been created.
Open the Build events tab in BundledDLLs's Project Properties page, and enter something like the following in the post-build textbox:
DEL "$(TargetDir)\$(TargetName).*"
(In case you wondered: The reason why you didn't add this project as a project reference to Main earlier is because if you had done so, Main would be looking for BundledDLLs.dll, which it wouldn't be able to find since you don't actually want such a file to be generated.)
P.S.: One disadvantage of adding such a post-build step is that it might interfere with incremental builds. If your project keeps getting recompiled from scratch after this, you might be better off removing the post-build step and living with the extra BundledDLLs.dll in your solution's output directory.
Another option is to use a makefile project, which doesn't require you to build/link anything.
In your project properties (right click property in solution explorer and click "Properties"), under "Configuration Properties" and then under "General", choose "Makefile" from the "Configuration Type" drop-down menu. The build output will include the warning "The property 'NMakeBuildCommandLine' doesn't exist...Skipping" but the build will succeed without building any dll/exe/etc.
While other answers here may better address your specific need, specifying a makefile more directly answers the question title "Possible to create Visual Studio project with Output Type of none?" I hope this is useful for people who google something to that effect and land here.
Credit goes to Xeek in the #winapi freenode irc channel for sharing this tip.
Instead of putting them in a project, you can put the files in a Solution Folder. One of your projects can have a build action that does the copying, but since they won't be in a project, they won't try to "build".