Not tracking C# designer-generated code: refuses to generate with clean checkout - asp.net

In our ASP.NET MVC project we have a Strings.resx file and the accompanying autogenerated Strings.Designer.cs file.
Tracking the Strings.Designer.cs file in source control creates a bunch of ugly merge conflicts and it's autogenerated anyway, so we decided to untrack it (remove it from source control and ignore the local copy of the file).
This works well, except that on a fresh checkout of the source the Strings.Designer.cs file doesn't exist. The PublicResXFileCodeGenerator that generates the file from Strings.resx balks with a warning:
"The custom tool 'PublicResXFileCodeGenerator' failed while processing the file 'Views\Setup\App_LocalResources\Strings.resx'."
And as a result, all of the strings in that file generate compile errors. This means you must manually right-click on each Strings.resx file in the project and choose "Run Custom Tool".
Is there any way to get the ResX code generator tool to run automatically even if Strings.Designer.cs doesn't yet exist?
(We've experimented with ResGen but it is finicky--it refuses to generate Strings files with the proper filename and namespace.)

You can use ResGen.exe to explicitly regenerate the .resources and .Designer.cs files from your .resx. Just throw a command that looks something like the following into your prebuild events:
ResGen.exe Strings.resx NameSpace.Strings.resources /publicClass /str:cs,"Your.Namespace",Strings,Strings.Designer.cs
...which will generate a Your.Namespace.Strings.resources file and a Strings.Designer.cs file w/ a "Strings" class in the "Your.Namespace" namespace.
(The /publicClass switch tells ResGen to generate public members, and "cs" is the C# language choice.)
Read more here: http://msdn.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx

Related

How to embedd Word 2007 document in ASP.NEt project

I have a neat class that is able to mergefields within a Word document based on a Datarow object containing the data I require to turn a Word 2007 docx template into a real Word document with the data embedded inside the Word document, and using OpenXML (forget Interop!). That's working for me.
However, I am having a royal pain to get the template loaded into my asp.net (.net2) project in Visual Studio 2005. Everytime I think I've "embedded" the Word document into the project, when I try and access it, I get this exception ...
Value cannot be null.
Parameter name: The Template File does not exists.
This error appears from a resource project (compiled in VS2008) DLL file that checks the existance of the file before it continues. I know that's the cause of the problem but why Fileinfo.Exists is always false, when I know the file is there!? The file is in the same server as the project resides, but in a different location to the project.
So the question really should say, why Fileinfo.Exists returns false all the time.
Never the less, I need to store this Word document inside the project itself, so my other need is to know how to embedd a Word document inside my asp.net project to keep it "contained" within the same one solution AND to get Fileinfo to recognise it DOES exist.
Thank you
I found it!
It was simply adding the file to my existing project using Add Existing ...
I then placed the file inside a folder within my project (any folder) and simply referencing it with ...
System.IO.File.Exists(Server.MapPath("FeedbackFormTemplate.docx"));
This generates a full path and filename with extension ready to be used elsewhere in the project.

Using Resource .resx file in Class library project

I have used resource file(.resx) file in a class library project to store some error messages. When I set the "Build Action" to "Embedded Resource" for the resx file and deploy it works fine. But I would like to separate the resource file from the dll since I may need to change the error messages in resx file in future without the need to recompiling the class library project. I tried the other option in "Build Action" property Content,resource, etc but nothing seems to be working in the way I require. When I use these property I am getting the below error,
Could not find any resources appropriate for the specified culture or the neutral culture. Make sure was correctly embedded or linked into assembly at compile time, or that all the satellite assemblies required are loadable and fully signed.
Is there any way to resolve this error and make it work?
Resource files have to be set to embedded - that's how they work.
You can create another assembly containing the resources and reference it - this way you can redeploy the updated resources. It requires a bit more work in your code (loading the assembly in order to be able to get the embedded resources).
However, from your description (text messages that need to be editable after deployment), perhaps storing these in configuration is a better option (in particular if you are not localizing).

How to run a .py (Python) file in ASP.NET?

I have a GetList.py file which consumes Web Service and saves the output in XML on the server.
How do I invoke GetList.py so it saves the output in XML on the server before displaying the XML output in .ASPX page?
You can create one batch file which contains call to python file and call that batch file from you .net application.
To call batch file, you can use Process class.
For example, suppose you have test.py file containing following code :
print "hello world"
then create one batch file (file having .bat extension) which has following contents :
python C:\test.py
Assuming you are using C#, and ur batchfile is stored in (C:\test.bat) you can use following code to invoke batch file
Process.Start("C:\test.bat");
You can have more details about Process class here
If your server has a Python interpreter installed, use that. (It's usually in /usr/bin/python)
If it doesn't (and it probably doesn't, since you use .NET), use IronPython. It's based on .NET and works very nicely with ASP.NET. Fair warning: if your GetList.py script uses parts of the CPython standard library that haven't been implemented in IronPython, you might have to change the script. See this article to get a basic intro to IronPython and see how it fits in with .NET.

ASP.NET - what files store method signature for xml web service?

i find this question tricky but what files store method signature info for xml webservice?
.dll, .asmx, .wsdl, .disco ?
TIA
It goes into a DLL once compiled, but it's in a code file when added to the project (referred to as a proxy class, it's in whatever language your project is). When you add a web reference it's imported this way. Updating the reference updates the .cs (or vb, whatever you're using).
If you want to see what happens, you can generate the code file yourself, see MSDN for details.
So overall: It is WSDL when fetched, converted to a code file when included (or updated), then finally compiled with the rest of your code into the DLL.

web.config - auto generate a release version

Simple task, but for some reason no simple solution just yet.
We've all got web.config files - and I haven't worked anywhere yet that doesn't have the problem where someone yells across the room "Sh*t, I've just uploaded the wrong web.config file".
Is there a simple way of being able to auto generate a web.config file that will contain the right things for copying to release? An example of these being:
Swap connection string over to use live database
Change
Switch over to use the live/release logging system, and live/release security settings
(in our case we need to change the SessionState mode to InProc from StateServer - this isn't normal)
If you have others, let me know and I'll update it here so it's easy for someone else to find
Maintaining 2 config files works, but is a royal pain, and is usually the reason something's gone wrong while you're pushing things live.
Visual Studio 2010 supports something like this. Check it out here.
How are you deploying your builds. In my environment, this used to be a pain point too, but now we use cruisecontrol.net and script our builds in nant. In our script, we detect the environment and have different versions of the config settings for each environment. See: http://www.mattwrock.com/post/2009/10/22/The-Perfect-Build-Part-3-Continuous-Integration-with-CruiseControlnet-and-NANT-for-Visual-Studio-Projects.aspx for my blogpost onthe subject of using cruisecontrol.net for build management. Skip to the end fora brief description of how we handle config versions.
In my most recent project I wrote a PowerShell script which loaded the web.config file, modified the necessary XML elements, and saved the file back out again. A bit like this:
param($mode, $src)
$ErrorActionPreference = "stop"
$config = [xml](Get-Content $src)
if ($mode -eq "Production")
{
$config.SelectSingleNode("/configuration/system.web/compilation").SetAttribute("debug", "false")
$config.SelectSingleNode("/configuration/system.web/customErrors").SetAttribute("mode", "off")
$config.SelectSingleNode("/configuration/system.net/mailSettings/smtp/network").SetAttribute("host", "live.mail.server")
$config.SelectSingleNode("/configuration/connectionStrings/add[#name='myConnectionString']").SetAttribute("connectionString", "Server=SQL; Database=Live")
}
elseif ($mode -eq "Testing")
{
# etc.
}
$config.Save($src)
This script overwrites the input file with the modifications, but it should be easy to modify it to save to a different file if needed. I have a build script that uses web deployment projects to build the web app, outputting the binaries minus the source code to a different folder - then the build script runs this script to rewrite web.config. The result is a folder containing all the files ready to be placed on the production server.
XSLT can be used to produce parameterized xml files. Web.config being xml file this approach works.
You can have one .xslt file(having xpath expressions).
Then there can be different xml files like
1. debug.config.xml
2. staging.config.xml
3. release.config.xml
Then in the postbuild event or using some msbuild tasks the xslt can be combined with appropriate xml files to having different web.config.
Sample debug.config.xml file can be
<Application.config>
<DatabaseServer></DatabaseServerName>
<ServiceIP></ServiceIP>
</Application.config>
.xslt can have xpaths referring to the xml given above.
Can have a look at the XSLT transformation This code can be used in some MSBuild tasks or nant tasks and different web.config's can be produced depending on the input config xml files.
This way you just have to manage the xml files.
There is only one overhead that the xslt file which is similar to web.config need to be managed. i.e whenever there is any tag getting added in the web.config the xslt also needs to be changed.
I don't think you can 100% avoid this.
The last years of work ever and ever shows: where human worked, there are fails.
So, here are 3 ideas from my last company, not the best maybe, but better then nothing:
Write an batch file or an C#.Net Application that change your web.config on a doubleclick
Write a "ToDo on Release"-List
Do pair-realesing (== pair programming while realease :))

Resources