I've written my first C#.NET WinForms application and am ready to publish the first build for users to install. I'm using log4net as my logging utility, and have it set as:
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="Logs\"/>
<param name="AppendToFile" value="true"/>
<param name="DatePattern" value="yyyy-MM-dd' Log.txt'" />
// etc
When I build my application, however, nothing ever gets logged. While running in visual studio, everything goes to /bin/Debug/Logs/yyyy-MM-dd Log.txt.
How do I specify where my program should install to, and what the working directory should be?
Keep in mind this program is fairly minimal (<6K lines of code) and I don't really know the difference in all the publishing types inside of visual studio. I just want to distribute an .exe to my users and track errors under a directory such as C:\Program Files\myapp. What am I doing wrong?
EDIT: When I right click the program and go to Properties from within the solution explorer, I'm setting the following options (which may be incorrect, I've never done this before):
Build -> All Configurations -> Output Path: C:\Program Files\myapp\bin\
Debug -> All Configurations -> Working directory: C:\Program Files\myapp\bin\
Publish -> Publish Location: C:\Program Files\myapp\Publish\
Publish Wizard -> Publish Location: C:\Program Files\myapp\Publish\
Publish Wizard -> From a CD-ROM or DVD-ROM
Publish Wizard -> The application will not check for updates
Are these settings correct or am I royally screwing something up? What I would like is for the user to be prompted an install location (defaulted to: C:\Program Files\myapp), and this location always be used for the working directory (so I know where the log file is). How do I achieve this?
Since you are using Click Once for deployment, the application will not be in the typical C:\Program Files\myapp directory.
Vista and Windows 7:
C:\Users\<UserName>\AppData\Local\Apps\2.0\<obscure foler>\<obscure folder>
Windows XP:
C:\Documents and Settings\<UserName>\LocalSettings\Apps\2.0\<obscure foler>\<obscure folder>
Dig around in those directories and you should see the log4net files.
Edit
An alternative to Click Once deployment is the Visual Studio installer: Walkthrough: Deploying a Windows-based Application. This will allow you to install the application in the standard C:\Program Files\myapp directory.
I'd recommend you create few dummy projects with the installer to gain some familiarity with the various options. Initially, creating MSI's with the installer can seem daunting if you haven't used it before; after a bit of usage, the VS installer will become quite easy to use.
Another suggestion would be to test your installers on a virtual machine so you don't do anything inadvertently in your personal environment.
When running in Visual Studio the log files get written under the Debug folder as that's where the exe is.
When you install the application to C:\Program Files\myapp (or where ever) the logs will be created relative to that location and so should be in C:\Program Files\myapp\Logs/yyyy-MM-dd Log.txt - assuming that the user has rights to create directories and files at that location.
The simplest way to prove this is to install the application and run it. Then check where the log file is created.
Related
This is pretty easy to replicate but also code here:
https://github.com/dominicshaw/dotnet-publish-error
create an empty wpf project using .NET7
create a publish profile for ClickOnce
publish via command line (not visual studio)
Publish profile is almost totally standard (view here)
Command line from project directory:
dotnet publish PublishError.csproj -p:PublishProfile=ClickOnceProfile
Subsequent error:
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\7.0.100\Microsoft.Common.CurrentVersion.targets(4149,5): error MSB4062: The "Microsoft.Build.Tasks.RequiresFr
amework35SP1Assembly" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKey
Token=b03f5f7f11d50a3a. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, a
nd that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\shawd\source\repos\PublishError\Publi
shError\PublishError.csproj]
I have the latest SDKs installed and VS2022 up to date. This only happens via command line - I am able to publish from Visual Studio (I am setting up devops, so require command line).
This happens regardless of adding nuget package for Microsoft.Build.Tasks.Core. Note however nuget package v15.1.0.0 is not available - I have tried 15.1.548 and the latest instead.
Totally at a loss! Any ideas very welcome.
Thanks vm
During the tests with your project and files, I finally managed to publish it successfully with the command dotnet publish PublishError.csproj -p:PublishProfile=FolderProfile.
Here is the document for dotnet publish, as is referred,
The preceding example uses the FolderProfile.pubxml file that is found
in the <project_folder>/Properties/PublishProfiles folder. If you
specify a path and file extension when setting the PublishProfile
property, they are ignored. MSBuild by default looks in the
Properties/PublishProfiles folder and assumes the pubxml file
extension.
And I also succeeded with dotnet publish with your project.
==============================
update on 11/19
So I suppose that the issue is resulted from your definition for -p:PublishProfile=ClickOnceProfile,it will change the path where this command would search for the publish file
A partial answer as my workaround for anyone struggling with a similar problem:
I have found it impossible to do this with the dotnet cli but I can do it with MSBuild if I specifically target 17.4 (VS2022). By default, my Azure DevOps Server 2020 capability is the 2019 MSBuild (15.X), so I have to be explicit:
"C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe" /restore /Verbosity:m /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release /p:PublishProfile=ClickOnceProfile
This works - so in my pipeline I have created a batch file which runs this, then I copy the files to my ClickOnce location.
Not ideal, but a working pipeline.
Interesting side note - this dotnet cli command which should be idenitical (and indeed uses the correct 17.4 MSBuild) - does not work (with the same error):
dotnet msbuild -target:Publish -property:RuntimeIdentifiers=win-x64;Configuration=Release;PublishProfile=ClickOnceProfile
I've a WinForms app and Database Project in the same solution.
How can I output dacpac of my database project in the WinForms output directory?
I created a routine using the Microsoft.SqlServer.Dac.dll to deploy the database. What I need to send in my deploy files to use this dll properly at stations that do not have a installed DACFramework?
It looks like you have two questions:
1 - How do you copy the dacpac to the bin directory of your winforms app?
A few ways:
Add a CopyFile msbuild task to the winforms project
Write a script you run when you want it copied
Manually?
2 - How do you use DacFx if it isn't installed?
You can copy the dll's from the dac\bin folder, you will also need to add the Microsoft.SqlServer.TransactSql.ScriptDom.dll that is in the sdk\assembly folder of a sql installation.
So the paths on my machine are:
C:\Program Files (x86)\Microsoft SQL Server\120\DAC\bin
C:\Program Files (x86)\Microsoft SQL Server\120\SDK\Assemblies
warning dll's from microsoft are not normally licensed to be copied as you want so if you are distributing them to clients, you may be legally required to install the DacFx.msi but that is one for your lawyers :)
ed
I'm attempting to build a .sqlproj on a TFS Build Server. I've followed the instructions here:
http://sqlproj.com/index.php/2012/03/headless-msbuild-support-for-ssdt-sqlproj-projects/
which I was directed to from here:
How to build .sqlproj projects on a build server?
But I still cannot build. The error is:
C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets
(441): The "SqlModelResolutionTask" task could not be instantiated
from "C:\Program Files
(x86)\Common7\IDE\Extensions\Microsoft\SQLDB\Dac\120\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll".
System.TypeInitializationException: The type initializer for
'Microsoft.Data.Tools.Schema.Tasks.Sql.DataTask' threw an exception.
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Data.Tools.Schema.Sql, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified. at
Microsoft.Data.Tools.Schema.Sql.Extensibility.ToolingShim.ConfigureExtensions()
--- End of inner exception stack trace --- at Microsoft.Data.Tools.Schema.Tasks.Sql.DataTask..ctor()
The SqlTasks.targets file, used by the SQL project, references this:
C:\Program Files (x86)\Common7\IDE\Extensions\Microsoft\SQLDB\Dac\120\Microsoft.Data.Tools.Schema.Tasks.Sql.11.dll
which in turn references the invalid version mentioned above.
However, the files installed by the process in the link above don't install this version. They do install version 10.3.0.0, which is referenced by
C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\Microsoft.Data.Tools.Schema.Tasks.Sql.12.dll
but this file is not the one used by the .targets file.
I don't know what the numbers at the end of this dll mean, but it seems odd to me that the one ending 12.dll references an earlier version of the one ending 11.dll.
I'm using Visual Studio 2013 and SQL Server 2012 - neither of which are installed on the build server, which I believe is the recommended situation. I don't know what the IDE folder is, or why the .targets file is using it.
I've spent about two days now trying to get this to build, but I'm out of ideas. Anyone know what's going on?
If you are running VS2013 SSDT is built into VS as long as you select it on the install screen. Install VS2013 with SSDT onto your build server. create a build definition and under Process > Build > Advanced Add the following to the MSBuild arguments to build the sql proj
/t:Build
if you have a publish profile and want to test publishing to SQL then add the publish switch and provide the link to the profile file
/t:Publish /p:SqlPublishProfilePath=MyDB.publish.xml.
this will publish the db to the server specified in the publish file.
the publish profile file can be created by opening the project in Visual Studio, right click on the project and select publish. Select save once you are happy with the publish options and then check in the file to source control so the build can find it, (project Root).
I was having this issue building a SQL Server project on an Azure DevOps CI/CD pipeline. None of the pre-built build tasks would work for me. And it is not possible to install a VS instance on the build server, I guess.
I solved this by avoiding to add a SQL Server project to the solution.
I achieved this by using an MSBuild SDK, capable of producing a SQL Server Data-Tier Application package (.dacpac) from the set of SQL scripts. By adding this second project to the solution, I managed to continue taking advantage of linking the project to a live database through SQL Server Object Explorer on Visual Studio. I gave a more detailed explanation in this answer.
The Publish feature stopped working once I installed Visual Studio 2012. Publish cannot find the prerequisite Microsoft .Net Framework 4 Client Profile (x86 and x64). Previously in Visual Studio 2010 this worked fine. I use 64-bit Windows 7.
The exact Visual Studio 2012 error message reads:
Error 104 - To enable 'Download prerequisites from the same location
as my application' in the Prerequisites dialog box, you must download file
'DotNetFX40Client\dotNetFx40_Client_x86_x64.exe' for item 'Microsoft .NET
Framework 4 Client Profile (x86 and x64)' to your local machine. For more
information, see http://go.microsoft.com/fwlink/?LinkId=239883
I placed the file dotNetFx40_Client_setup.exe in the location:
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper\Packages\DotNetFX40Client
I also left it in it's original location (note the v7.0A):
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\DotNetFX40Client
Edit (after solving the problem): I see that the correct setup file (dotNetFx40_Client_x86_x64.exe) is actually in the v7.0A folder. Had I just copied it from there everything would have worked (rather than downloading the wrong setup).
Publish works fine when I change the option "Download prerequisites from the same location as my application" to "Download prerequisites from the component vendor's website" (at project Properties -> Publish -> Prerequisites...)
I noticed a yellow exclamation point beside the (checked) "Windows Installer 3.1" with the warning: "Prerequisite could not be found for bootstrapping". For that I have the file WindowsInstaller-KB893803-v2-x86.exe in the folder:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\WindowsInstaller3_1
The application has run fine within my company's network for the past year when published with Visual Studio 2010. I opened the solution file in VS 2012 (for the first time) and it compiles and runs fine locally. Only the Publish feature is broken.
Am I missing something? Where is ClickOnce Publish expecting to find these prerequisites for my WPF application?
I'm answering my own question. The problem went away when I used a different .Net 4 Client setup program. The exe that works for me is dotNetFx40_Client_x86_x64.exe found at:
http://www.microsoft.com/en-us/download/details.aspx?id=24872
The wrong setup program is dotNetFx40_Client_setup.exe which I was led to by following the Microsoft MSDN help topic How to: Include Prerequisites with a ClickOnce Application (Visual Studio 2012) which led me to this link to the setup. I use Chrome which downloaded the web installer which I didn't realize was not the file I needed. Had I been using IE none of this would have happened. I was clued into the problem by this StackOverflow question which suggests renaming the setup program. Instead of renaming it I just downloaded the correct one.
re: Windows installer: VS2012 doesn't include the same prerequisites as VS2010, but you can copy the package from the previous SDK folders to the new one, and it will magically show up in the prerequisite list in VS2012 and work!
Is there an easy way to create Silverlight 3 applications with F# (October CTP)?
I have seen the F# for Silverlight, but that only works with the May CTP.
I am using Visual Studio Integrated Shell 2008.
It is possible to use the May CTP templates with the October CTP version of F#
Create your new project, then unload it and edit the hint path for the FSharp.Core.dll to point to the October CTP,
<HintPath>$(ProgramFiles)\fsharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll</HintPath>
then reload the project and build.
You do have to package the .xap file manually by e.g. using the chiron tool (or just zipping and renaming)
The AppManifest.xaml file looks like
<Deployment xmlns="http://schemas.microsoft.com/client/2007/deployment"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RuntimeVersion="3.0.40818.0"
EntryPointAssembly="astroclock-fs"
EntryPointType="astroclock.fs.MyApp">
<Deployment.Parts>
<AssemblyPart x:Name="astroclock-fs" Source="astroclock-fs.dll" />
<AssemblyPart x:Name="FSharp.Core" Source="FSharp.Core.dll" />
</Deployment.Parts>
</Deployment>
where you fill in your own assembly name and entrypoint instead of mine
Create a folder in $(ProjectDir) to hold all the files to be packaged and copy C:\Program Files\FSharp-1.9.7.8\Silverlight\2.0\bin\FSharp.Core.dll into it, along with the AppManifest.xaml above
Create an empty file null.py in the folder to keep chiron quiet if you are using that tool
Add the following post-build steps
cd $(ProjectDir)
copy /y $(OutDir)$(TargetFileName) [your directory with all the output]
"C:\Program Files\IronPython 2.0\Silverlight\bin\chiron.exe" /d:[your directory with all the output] /z:app.xap
Create a test page to load app.xap
Build project
Load page in browser and enjoy
ADDED
You can make a permanent fix for the hint path needed to find FSharp.Core.dll by editing the template in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplatesCache\FSharp\Silverlight\SilverlightLibrary3.zip\SilverlightLibrary.fsproj (and probably the version of the file in C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\FSharp\Silverlight\SilverlightLibrary3.zip just to be certain).
And a working proof of concept (source and everything bundled into the xap) here.
Looks like I got to wait for VS 2010.