Exclude certain files from compiling in directory - c#

I am trying to create multi file assembly by creating .netmodules for respective Visual Studio projects. These .netmodules are being created successfully. Command used to produce the modules:
csc.exe "/out:$(ProjectDir)$(ProjectName).netmodule" "/t:module" "/recurse:$(ProjectDir)*.cs"
The problem with the above command is the switch :/recurse:$(ProjectDir)*.cs, which compiles all files in the project including AssemblyInfo.cs file. This file is compiled for each project.
At the end when I am trying to build a multi file assembly using following command:
csc.exe /t:library /out:MultiFile.dll /addmodule:Foo.netmodule /addmodule:Boo.netmodule
I get the error error CS7061: Duplicate 'GuidAttribute' attribute in 'Foo.netmodule'
Please state any ways to create multi file assembly.
As of me, I can think of two ways, deleting the AssemblyInfo.cs files from project or find a way to exclude the specific files from compiling in the /recurse switch (don't know how to exclude the file).

Although it would be nice to pass some parameter to CSC.exe to exclude some files from /recurse switch. I did not find it anywhere.
Solution I opted for:
Copy all source files for each Visual Studio project to different folder, excluding the AssemblyInfo.cs file.
Compile all the files from that folder to produce .netmodule.

Related

Visual Studio Extension, dll deployment and locking [C#, VSIX]

I need some help using CodeAnalysisCSharp in my VSIX project.
The issue I'm currently having is that the necessary dlls are not "deployed" when installing the extension. I've had to manually copy/paste these files to the C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE folder, for it to "work".
System.Numerics.Vectors.dll
System.Runtime.CompilerServices.Unsafe.dll
System.Memory.dll
Microsoft.CodeAnalysis.dll
Microsoft.CodeAnalysis.CSharp.dll
I have created an extension project and added a custom command. This command should be able to use the CodeAnalysisCSharp to navigate the syntax tree of a C# file.
I'd very much like for the installer file (.vsix) to be able to deploy the dll dependencies, just like you'd expect it to, I just don't know how or where to look to make this happen.
Thanks in advance.
I found out that if you use the vsixmanifest file to add assets, and give it a sub folder, it doesn't get packaged correctlty. The files will be copied correctly, but the reference to the dlls are not correct, so you get a "dll not found" exception.
In general the vsixmanifest designer, seems to be riddled with quirks where you need to edit the xml code to be sure that the values are set correctly.

Msbuild not producing XML file with code analysis

I have been digging but cannot find the answer - I THOUGHT I had found it in this question but it is not working on my system. The only difference that I can see is that I am giving msbuild a solution file and not an individual project file - must I do it at the project level to get output? The command line I entered was:
msbuild Interlink.NET.sln /p:RunCodeAnalysis=true /p:CodeAnalysisLogFile=test.xml
Obviously, test.xml was not created or I would not be asking this question...
The solution is a C# project in VS2015, in case any of that effects things. In Visual Studio, I can select "Analyze | Run Code Analysis on Solution" and things work as expected. I want to incorporate the analysis into an automated build process and produce an XML file with the analysis.
Well yes the command that you used is correct and will work for .sln files.
Only a test.xml file will be created inside each of the constituent projects.
And these copies will contain the static code analysis reports of that specific prject.
It will not be created at the level of the .sln file.
I ran msbuild with the following arguments and the xml file got produced in the output directory, but the filename I've given got ignored. It was named vc.nativecodeanalysis.all.xml instead.
msbuild Project.sln /p:Configuration=Release /p:Platform=x64 /p:RunCodeAnalysis=true /p:CodeAnalysisLogFile=test.xml /t:Clean;Rebuild
Project.sln is a C++ project in VS2017 though.
Please refer to the below forum
https://stackoverflow.com/questions/30472569/how-to-get-an-xml-report-out-of-msbuild-code-analysis
msbuild MyProject.csproj /p:RunCodeAnalysis=true /p:CodeAnalysisLogFile=MyXmlReport.xml

Visual Studio 2010 Manage Output Files

I'm new about code developing with Visual Studio 2010 and I would like to ask you a simple question about something after build a project.
I have a C# project and when I build It in Release mode some file are created and some of them copied from another in to \output\bin\Release\ folder. My question is that How can I manage that which created dll or created file will be in \output\bin\Release\ folder.
I tried to take a look at build properties of project but I could not find any option about it.
Thank you.
Actually I do not need this dll in my project output folder because I
add this dlls as a reference to my project
And this is exactly why this file appear in output folder.
There are several ways to "put" file in output folder. For normal files in the project you can set property Copy to Output Directory.
If we talking about dll's, (as mentioned Hans), there is Copy Local property for each assembly in References.
By default VS set this according to our GAC, so if you are using 3rd part assembly or from another project VS will set this property to True and file will be copied to output folder.
If you don't want to put this file in output folder, just set this property to False. But remember, at run time this assembly should exist.
For more information: How to: Set the Copy Local Property of a Reference
Another explanation: you just messed up with Output path in the project properties and two project has the same output folder. :)
I suggest that you ignore the extra files that are created. One way to do this is to configure the destination of these to a different location.
I use this:
property pages->General
- Output Directory = $(SolutionDir)..\link\
- Intermediate Directory = c:\temp\vc10\$(SolutionName)\$(Configuration)\
Use the same settings for debug and release.

How do I add a folder to a program's namespace?

I recently converted a Visual Studio 2006 project up to Visual Studio 2010. The conversion went over fine, but somewhere along the line the namespace got corrupted, and as a result, parts of the codebase are throwing errors (because the objects they're referencing, etc. are no longer being imported).
I can manually locate the folder with the relevant files, but can't seem to reference the file with using clauses (or I'm botching using entirely). Is there some function in visual studio I can use to import the requisite files directly?
For physical files you can click the Show All Files button at the top of the solution explorer, then locating the folder, right click and choose Include in Project.
if you can get Resharper installed, it will try to hint you the namespace. if upgrade missed to add some files, then you should add them manually and recompile. i am not sure if you can requisite the files directly
The using directive has nothing to do with the folder where the file is located, it is only depending on the name after the "namespace" keyword inside each file.
In some projects people name their namespaces similar to the folder structure but to the c# compiler that is just a coincidence.

Find out all the files required to run a c# application

I need to generate a list of all the files which are enough to run my application on any machine. I need this for a setup program. When i go to bin/release folder i'm able to see some pdb files and some configuration files, which i think will not be needed. I tried to disable generation of pdb files too but it still generates pdb for the other projects present in the solution.
So i need a way in visual studio 2008, which can get me all the files (the .exe and .dll and other files) required by my application to run.
Thanks.
Have you tried publishing the application (Build > Publish [app])?
This should just copy all the essential files to the specified folder.
The pdb files are used for debugging. Building in "Release" mode should exclude these files.
You can also create a setup project within the solution. Using that project it is possible to see a list of included files.
If you make a release build or publish the application then you should have a complete set of assemblies your application needs.
However, it can still rely on assemblies which reside in the GAC (Global Assembly Cache) of your machine. Check the references of your project if you think there are assemblies missing in the bin folder.
To solve this exact problem with our software, we wrote a simple console app that finds all the .vbproj & .csproj files in our projects directory, then changes all of the to Release mode (which does not create pdb files, documentation files etc).
This is then run by the build machine (CruiseControl.Net) before it starts compiling the projects.

Categories